home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / rpm / db.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-10-22  |  89.7 KB  |  2,299 lines

  1. /*
  2.  * See the file LICENSE for redistribution information.
  3.  *
  4.  * Copyright (c) 1996-2004
  5.  *    Sleepycat Software.  All rights reserved.
  6.  *
  7.  * $Id: db.in,v 11.463 2004/10/11 18:47:50 bostic Exp $
  8.  *
  9.  * db.h include file layout:
  10.  *    General.
  11.  *    Database Environment.
  12.  *    Locking subsystem.
  13.  *    Logging subsystem.
  14.  *    Shared buffer cache (mpool) subsystem.
  15.  *    Transaction subsystem.
  16.  *    Access methods.
  17.  *    Access method cursors.
  18.  *    Dbm/Ndbm, Hsearch historic interfaces.
  19.  */
  20.  
  21. #ifndef _DB_H_
  22. #define    _DB_H_
  23.  
  24. #ifndef __NO_SYSTEM_INCLUDES
  25. #include <sys/types.h>
  26. #include <inttypes.h>
  27. #include <stdint.h>
  28. #include <stddef.h>
  29. #include <stdio.h>
  30. #endif
  31.  
  32. #if defined(__cplusplus)
  33. extern "C" {
  34. #endif
  35.  
  36.  
  37. #undef __P
  38. #define    __P(protos)    protos
  39.  
  40. /*
  41.  * Berkeley DB version information.
  42.  */
  43. #define    DB_VERSION_MAJOR    4
  44. #define    DB_VERSION_MINOR    3
  45. #define    DB_VERSION_PATCH    27
  46. #define    DB_VERSION_STRING    "Sleepycat Software: Berkeley DB 4.3.27: (December 22, 2004)"
  47.  
  48. /*
  49.  * !!!
  50.  * Berkeley DB uses specifically sized types.  If they're not provided by
  51.  * the system, typedef them here.
  52.  *
  53.  * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
  54.  * as does BIND and Kerberos, since we don't know for sure what #include
  55.  * files the user is using.
  56.  *
  57.  * !!!
  58.  * We also provide the standard u_int, u_long etc., if they're not provided
  59.  * by the system.
  60.  */
  61. #ifndef    __BIT_TYPES_DEFINED__
  62. #define    __BIT_TYPES_DEFINED__
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. #endif
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. /*
  79.  * uintmax_t --
  80.  * Largest unsigned type, used to align structures in memory.  We don't store
  81.  * floating point types in structures, so integral types should be sufficient
  82.  * (and we don't have to worry about systems that store floats in other than
  83.  * power-of-2 numbers of bytes).  Additionally this fixes compilers that rewrite
  84.  * structure assignments and ANSI C memcpy calls to be in-line instructions
  85.  * that happen to require alignment.  Note: this alignment isn't sufficient for
  86.  * mutexes, which depend on things like cache line alignment.  Mutex alignment
  87.  * is handled separately, in mutex.h.
  88.  *
  89.  * uintptr_t --
  90.  * Unsigned type that's the same size as a pointer.  There are places where
  91.  * DB modifies pointers by discarding the bottom bits to guarantee alignment.
  92.  * We can't use uintmax_t, it may be larger than the pointer, and compilers
  93.  * get upset about that.  So far we haven't run on any machine where there's
  94.  * no unsigned type the same size as a pointer -- here's hoping.
  95.  */
  96.  
  97.  
  98.  
  99. /*
  100.  * Sequences are only available on machines with 64-bit integral types.
  101.  */
  102. typedef int64_t db_seq_t;
  103.  
  104. /* Basic types that are exported or quasi-exported. */
  105. /*@-incondefs -fielduse -enummemuse -typeuse @*/
  106. typedef    u_int32_t    db_pgno_t;    /* Page number type. */
  107. typedef    u_int16_t    db_indx_t;    /* Page offset type. */
  108. #define    DB_MAX_PAGES    0xffffffff    /* >= # of pages in a file */
  109.  
  110. typedef    u_int32_t    db_recno_t;    /* Record number type. */
  111. #define    DB_MAX_RECORDS    0xffffffff    /* >= # of records in a tree */
  112.  
  113. typedef u_int32_t    db_timeout_t;    /* Type of a timeout. */
  114.  
  115. /*
  116.  * Region offsets are the difference between a pointer in a region and the
  117.  * region's base address.  With private environments, both addresses are the
  118.  * result of calling malloc, and we can't assume anything about what malloc
  119.  * will return, so region offsets have to be able to hold differences between
  120.  * arbitrary pointers.
  121.  */
  122. typedef    uintptr_t    roff_t;
  123.  
  124. /*
  125.  * Forward structure declarations, so we can declare pointers and
  126.  * applications can get type checking.
  127.  */
  128. struct __db;        typedef struct __db DB;
  129. struct __db_bt_stat;    typedef struct __db_bt_stat DB_BTREE_STAT;
  130. struct __db_cipher;    typedef struct __db_cipher DB_CIPHER;
  131. struct __db_dbt;    typedef struct __db_dbt DBT;
  132. struct __db_env;    typedef struct __db_env DB_ENV;
  133. struct __db_h_stat;    typedef struct __db_h_stat DB_HASH_STAT;
  134. struct __db_ilock;    typedef struct __db_ilock DB_LOCK_ILOCK;
  135. struct __db_lock_stat;    typedef struct __db_lock_stat DB_LOCK_STAT;
  136. struct __db_lock_u;    typedef struct __db_lock_u DB_LOCK;
  137. struct __db_lockreq;    typedef struct __db_lockreq DB_LOCKREQ;
  138. struct __db_log_cursor;    typedef struct __db_log_cursor DB_LOGC;
  139. struct __db_log_stat;    typedef struct __db_log_stat DB_LOG_STAT;
  140. struct __db_lsn;    typedef struct __db_lsn DB_LSN;
  141. struct __db_mpool;    typedef struct __db_mpool DB_MPOOL;
  142. struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
  143. struct __db_mpool_stat;    typedef struct __db_mpool_stat DB_MPOOL_STAT;
  144. struct __db_mpoolfile;    typedef struct __db_mpoolfile DB_MPOOLFILE;
  145. struct __db_preplist;    typedef struct __db_preplist DB_PREPLIST;
  146. struct __db_qam_stat;    typedef struct __db_qam_stat DB_QUEUE_STAT;
  147. struct __db_rep;    typedef struct __db_rep DB_REP;
  148. struct __db_rep_stat;    typedef struct __db_rep_stat DB_REP_STAT;
  149. struct __db_sequence;    typedef struct __db_sequence DB_SEQUENCE;
  150. struct __db_seq_record; typedef struct __db_seq_record DB_SEQ_RECORD;
  151. struct __db_seq_stat;    typedef struct __db_seq_stat DB_SEQUENCE_STAT;
  152. struct __db_txn;    typedef struct __db_txn DB_TXN;
  153. struct __db_txn_active;    typedef struct __db_txn_active DB_TXN_ACTIVE;
  154. struct __db_txn_stat;    typedef struct __db_txn_stat DB_TXN_STAT;
  155. struct __db_txnmgr;    typedef struct __db_txnmgr DB_TXNMGR;
  156. struct __dbc;        typedef struct __dbc DBC;
  157. struct __dbc_internal;    typedef struct __dbc_internal DBC_INTERNAL;
  158. struct __fh_t;        typedef struct __fh_t DB_FH;
  159. struct __fname;        typedef struct __fname FNAME;
  160. struct __key_range;    typedef struct __key_range DB_KEY_RANGE;
  161. /*@=incondefs@*/
  162. struct __mpoolfile;    typedef struct __mpoolfile MPOOLFILE;
  163. struct __mutex_t;    typedef struct __mutex_t DB_MUTEX;
  164.  
  165. /* Key/data structure -- a Data-Base Thang. */
  166. struct __db_dbt {
  167.     /*
  168.      * data/size must be fields 1 and 2 for DB 1.85 compatibility.
  169.      */
  170.     void     *data;            /* Key/data */
  171.     u_int32_t size;            /* key/data length */
  172.  
  173.     u_int32_t ulen;            /* RO: length of user buffer. */
  174.     u_int32_t dlen;            /* RO: get/put record length. */
  175.     u_int32_t doff;            /* RO: get/put record offset. */
  176.  
  177. #define    DB_DBT_APPMALLOC    0x001    /* Callback allocated memory. */
  178. #define    DB_DBT_ISSET        0x002    /* Lower level calls set value. */
  179. #define    DB_DBT_MALLOC        0x004    /* Return in malloc'd memory. */
  180. #define    DB_DBT_PARTIAL        0x008    /* Partial put/get. */
  181. #define    DB_DBT_REALLOC        0x010    /* Return in realloc'd memory. */
  182. #define    DB_DBT_USERMEM        0x020    /* Return in user's memory. */
  183. #define    DB_DBT_DUPOK        0x040    /* Insert if duplicate. */
  184.     u_int32_t flags;
  185. };
  186.  
  187. /*
  188.  * Common flags --
  189.  *    Interfaces which use any of these common flags should never have
  190.  *    interface specific flags in this range.
  191.  */
  192. #define    DB_CREATE          0x0000001    /* Create file as necessary. */
  193. #define    DB_CXX_NO_EXCEPTIONS  0x0000002    /* C++: return error values. */
  194. #define    DB_FORCE          0x0000004    /* Force (anything). */
  195. #define    DB_NOMMAP          0x0000008    /* Don't mmap underlying file. */
  196. #define    DB_RDONLY          0x0000010    /* Read-only (O_RDONLY). */
  197. #define    DB_RECOVER          0x0000020    /* Run normal recovery. */
  198. #define    DB_THREAD          0x0000040    /* Applications are threaded. */
  199. #define    DB_TRUNCATE          0x0000080    /* Discard existing DB (O_TRUNC). */
  200. #define    DB_TXN_NOSYNC          0x0000100    /* Do not sync log on commit. */
  201. #define    DB_TXN_NOT_DURABLE    0x0000200    /* Do not log changes. */
  202. #define    DB_USE_ENVIRON          0x0000400    /* Use the environment. */
  203. #define    DB_USE_ENVIRON_ROOT   0x0000800    /* Use the environment if root. */
  204.  
  205. /*
  206.  * Common flags --
  207.  *    Interfaces which use any of these common flags should never have
  208.  *    interface specific flags in this range.
  209.  *
  210.  * DB_AUTO_COMMIT:
  211.  *    DB_ENV->set_flags, DB->associate, DB->del, DB->put, DB->open,
  212.  *    DB->remove, DB->rename, DB->truncate
  213.  * DB_DEGREE_2:
  214.  *    DB->cursor, DB->get, DB->join, DBcursor->c_get, DB_ENV->txn_begin
  215.  * DB_DIRTY_READ:
  216.  *    DB->cursor, DB->get, DB->join, DB->open, DBcursor->c_get,
  217.  *    DB_ENV->txn_begin
  218.  * DB_NOAUTO_COMMIT
  219.  *    DB->associate, DB->del, DB->put, DB->open,
  220.  *    DB->remove, DB->rename, DB->truncate
  221.  *
  222.  * !!!
  223.  * The DB_DIRTY_READ and DB_DEGREE_2 bit masks can't be changed without
  224.  * also changing the masks for the flags that can be OR'd into DB
  225.  * access method and cursor operation values.
  226.  */
  227. #define    DB_AUTO_COMMIT          0x01000000/* Implied transaction. */
  228. #define    DB_DEGREE_2          0x02000000/* Degree 2. */
  229. #define    DB_DIRTY_READ          0x04000000/* Dirty Read. */
  230. #define    DB_NO_AUTO_COMMIT     0x08000000/* Override env-wide AUTOCOMMIT. */
  231.  
  232. /*
  233.  * Flags private to db_env_create.
  234.  */
  235. #define    DB_RPCCLIENT          0x0000001    /* An RPC client environment. */
  236.  
  237. /*
  238.  * Flags private to db_create.
  239.  */
  240. #define    DB_REP_CREATE          0x0000001    /* Open of an internal rep database. */
  241. #define    DB_XA_CREATE          0x0000002    /* Open in an XA environment. */
  242.  
  243. /*
  244.  * Flags private to DB_ENV->open.
  245.  *       Shared flags up to 0x0000800 */
  246. #define    DB_INIT_CDB          0x0001000    /* Concurrent Access Methods. */
  247. #define    DB_INIT_LOCK          0x0002000    /* Initialize locking. */
  248. #define    DB_INIT_LOG          0x0004000    /* Initialize logging. */
  249. #define    DB_INIT_MPOOL          0x0008000    /* Initialize mpool. */
  250. #define    DB_INIT_REP          0x0010000    /* Initialize replication. */
  251. #define    DB_INIT_TXN          0x0020000    /* Initialize transactions. */
  252. #define    DB_JOINENV          0x0040000    /* Initialize all subsystems present. */
  253. #define    DB_LOCKDOWN          0x0080000    /* Lock memory into physical core. */
  254. #define    DB_PRIVATE          0x0100000    /* DB_ENV is process local. */
  255. #define    DB_RECOVER_FATAL      0x0200000    /* Run catastrophic recovery. */
  256. #define    DB_SYSTEM_MEM          0x0400000    /* Use system-backed memory. */
  257.  
  258. /*
  259.  * Flags private to DB->open.
  260.  *       Shared flags up to 0x0000800 */
  261. #define    DB_EXCL              0x0001000    /* Exclusive open (O_EXCL). */
  262. #define    DB_FCNTL_LOCKING      0x0002000    /* UNDOC: fcntl(2) locking. */
  263. #define    DB_RDWRMASTER          0x0004000    /* UNDOC: allow subdb master open R/W */
  264. #define    DB_WRITEOPEN          0x0008000    /* UNDOC: open with write lock. */
  265.  
  266. /*
  267.  * Flags private to DB_ENV->txn_begin.
  268.  *       Shared flags up to 0x0000800 */
  269. #define    DB_TXN_NOWAIT          0x0001000    /* Do not wait for locks in this TXN. */
  270. #define    DB_TXN_SYNC          0x0002000    /* Always sync log on commit. */
  271.  
  272. /*
  273.  * Flags private to DB_ENV->set_encrypt.
  274.  */
  275. #define    DB_ENCRYPT_AES          0x0000001    /* AES, assumes SHA1 checksum */
  276.  
  277. /*
  278.  * Flags private to DB_ENV->set_flags.
  279.  *       Shared flags up to 0x00000800 */
  280. #define    DB_CDB_ALLDB          0x00001000/* Set CDB locking per environment. */
  281. #define    DB_DIRECT_DB          0x00002000/* Don't buffer databases in the OS. */
  282. #define    DB_DIRECT_LOG          0x00004000/* Don't buffer log files in the OS. */
  283. #define    DB_DSYNC_LOG          0x00008000/* Set O_DSYNC on the log. */
  284. #define    DB_LOG_AUTOREMOVE     0x00010000/* Automatically remove log files. */
  285. #define    DB_LOG_INMEMORY       0x00020000/* Store logs in buffers in memory. */
  286. #define    DB_NOLOCKING          0x00040000/* Set locking/mutex behavior. */
  287. #define    DB_NOPANIC          0x00080000/* Set panic state per DB_ENV. */
  288. #define    DB_OVERWRITE          0x00100000/* Overwrite unlinked region files. */
  289. #define    DB_PANIC_ENVIRONMENT  0x00200000/* Set panic state per environment. */
  290. #define    DB_REGION_INIT          0x00400000/* Page-fault regions on open. */
  291. #define    DB_TIME_NOTGRANTED    0x00800000/* Return NOTGRANTED on timeout. */
  292. /*          Shared flags at 0x01000000 */
  293. /*          Shared flags at 0x02000000 */
  294. /*          Shared flags at 0x04000000 */
  295. /*          Shared flags at 0x08000000 */
  296. #define    DB_TXN_WRITE_NOSYNC   0x10000000/* Write, don't sync, on txn commit. */
  297. #define    DB_YIELDCPU          0x20000000/* Yield the CPU (a lot). */
  298.  
  299. /*
  300.  * Flags private to DB->set_feedback's callback.
  301.  */
  302. #define    DB_UPGRADE          0x0000001    /* Upgrading. */
  303. #define    DB_VERIFY          0x0000002    /* Verifying. */
  304.  
  305. /*
  306.  * Flags private to DB_MPOOLFILE->open.
  307.  *       Shared flags up to 0x0000800 */
  308. #define    DB_DIRECT          0x0001000    /* Don't buffer the file in the OS. */
  309. #define    DB_DURABLE_UNKNOWN    0x0002000 /* internal: durability on open. */
  310. #define    DB_EXTENT          0x0004000    /* internal: dealing with an extent. */
  311. #define    DB_ODDFILESIZE          0x0008000    /* Truncate file to N * pgsize. */
  312.  
  313. /*
  314.  * Flags private to DB->set_flags.
  315.  */
  316. #define    DB_CHKSUM          0x0000001    /* Do checksumming */
  317. #define    DB_DUP              0x0000002    /* Btree, Hash: duplicate keys. */
  318. #define    DB_DUPSORT          0x0000004    /* Btree, Hash: duplicate keys. */
  319. #define    DB_ENCRYPT          0x0000008    /* Btree, Hash: duplicate keys. */
  320. #define    DB_INORDER          0x0000010    /* Queue: strict ordering on consume. */
  321. #define    DB_RECNUM          0x0000020    /* Btree: record numbers. */
  322. #define    DB_RENUMBER          0x0000040    /* Recno: renumber on insert/delete. */
  323. #define    DB_REVSPLITOFF          0x0000080    /* Btree: turn off reverse splits. */
  324. #define    DB_SNAPSHOT          0x0000100    /* Recno: snapshot the input. */
  325.  
  326. /*
  327.  * Flags private to the DB_ENV->stat_print, DB->stat and DB->stat_print methods.
  328.  */
  329. #define    DB_STAT_ALL          0x0000001    /* Print: Everything. */
  330. #define    DB_STAT_CLEAR          0x0000002    /* Clear stat after returning values. */
  331. #define    DB_STAT_LOCK_CONF     0x0000004    /* Print: Lock conflict matrix. */
  332. #define    DB_STAT_LOCK_LOCKERS  0x0000008    /* Print: Lockers. */
  333. #define    DB_STAT_LOCK_OBJECTS  0x0000010    /* Print: Lock objects. */
  334. #define    DB_STAT_LOCK_PARAMS   0x0000020    /* Print: Lock parameters. */
  335. #define    DB_STAT_MEMP_HASH     0x0000040    /* Print: Mpool hash buckets. */
  336. #define    DB_STAT_SUBSYSTEM     0x0000080    /* Print: Subsystems too. */
  337.  
  338. /*
  339.  * Flags private to DB->join.
  340.  */
  341. #define    DB_JOIN_NOSORT          0x0000001    /* Don't try to optimize join. */
  342.  
  343. /*
  344.  * Flags private to DB->verify.
  345.  */
  346. #define    DB_AGGRESSIVE          0x0000001    /* Salvage whatever could be data.*/
  347. #define    DB_NOORDERCHK          0x0000002    /* Skip sort order/hashing check. */
  348. #define    DB_ORDERCHKONLY          0x0000004    /* Only perform the order check. */
  349. #define    DB_PR_PAGE          0x0000008    /* Show page contents (-da). */
  350. #define    DB_PR_RECOVERYTEST    0x0000010    /* Recovery test (-dr). */
  351. #define    DB_PRINTABLE          0x0000020    /* Use printable format for salvage. */
  352. #define    DB_SALVAGE          0x0000040    /* Salvage what looks like data. */
  353. #define    DB_UNREF          0x0000080    /* Report unreferenced pages. */
  354. /*
  355.  * !!!
  356.  * These must not go over 0x8000, or they will collide with the flags
  357.  * used by __bam_vrfy_subtree.
  358.  */
  359.  
  360. /*
  361.  * Flags private to DB->set_rep_transport's send callback.
  362.  */
  363. #define    DB_REP_NOBUFFER          0x0000001    /* Do not buffer this message. */
  364. #define    DB_REP_PERMANENT      0x0000002    /* Important--app. may want to flush. */
  365.  
  366. /*******************************************************
  367.  * Locking.
  368.  *******************************************************/
  369. #define    DB_LOCKVERSION    1
  370.  
  371. #define    DB_FILE_ID_LEN        20    /* Unique file ID length. */
  372.  
  373. /*
  374.  * Deadlock detector modes; used in the DB_ENV structure to configure the
  375.  * locking subsystem.
  376.  */
  377. #define    DB_LOCK_NORUN        0
  378. #define    DB_LOCK_DEFAULT        1    /* Default policy. */
  379. #define    DB_LOCK_EXPIRE        2    /* Only expire locks, no detection. */
  380. #define    DB_LOCK_MAXLOCKS    3    /* Select locker with max locks. */
  381. #define    DB_LOCK_MAXWRITE    4    /* Select locker with max writelocks. */
  382. #define    DB_LOCK_MINLOCKS    5    /* Select locker with min locks. */
  383. #define    DB_LOCK_MINWRITE    6    /* Select locker with min writelocks. */
  384. #define    DB_LOCK_OLDEST        7    /* Select oldest locker. */
  385. #define    DB_LOCK_RANDOM        8    /* Select random locker. */
  386. #define    DB_LOCK_YOUNGEST    9    /* Select youngest locker. */
  387.  
  388. /* Flag values for lock_vec(), lock_get(). */
  389. #define    DB_LOCK_ABORT        0x001    /* Internal: Lock during abort. */
  390. #define    DB_LOCK_NOWAIT        0x002    /* Don't wait on unavailable lock. */
  391. #define    DB_LOCK_RECORD        0x004    /* Internal: record lock. */
  392. #define    DB_LOCK_REMOVE        0x008    /* Internal: flag object removed. */
  393. #define    DB_LOCK_SET_TIMEOUT    0x010    /* Internal: set lock timeout. */
  394. #define    DB_LOCK_SWITCH        0x020    /* Internal: switch existing lock. */
  395. #define    DB_LOCK_UPGRADE        0x040    /* Internal: upgrade existing lock. */
  396.  
  397. /*
  398.  * Simple R/W lock modes and for multi-granularity intention locking.
  399.  *
  400.  * !!!
  401.  * These values are NOT random, as they are used as an index into the lock
  402.  * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
  403.  * must be == 4.
  404.  */
  405. typedef enum {
  406.     DB_LOCK_NG=0,            /* Not granted. */
  407.     DB_LOCK_READ=1,            /* Shared/read. */
  408.     DB_LOCK_WRITE=2,        /* Exclusive/write. */
  409.     DB_LOCK_WAIT=3,            /* Wait for event */
  410.     DB_LOCK_IWRITE=4,        /* Intent exclusive/write. */
  411.     DB_LOCK_IREAD=5,        /* Intent to share/read. */
  412.     DB_LOCK_IWR=6,            /* Intent to read and write. */
  413.     DB_LOCK_DIRTY=7,        /* Dirty Read. */
  414.     DB_LOCK_WWRITE=8        /* Was Written. */
  415. } db_lockmode_t;
  416.  
  417. /*
  418.  * Request types.
  419.  */
  420. typedef enum {
  421.     DB_LOCK_DUMP=0,            /* Display held locks. */
  422.     DB_LOCK_GET=1,            /* Get the lock. */
  423.     DB_LOCK_GET_TIMEOUT=2,        /* Get lock with a timeout. */
  424.     DB_LOCK_INHERIT=3,        /* Pass locks to parent. */
  425.     DB_LOCK_PUT=4,            /* Release the lock. */
  426.     DB_LOCK_PUT_ALL=5,        /* Release locker's locks. */
  427.     DB_LOCK_PUT_OBJ=6,        /* Release locker's locks on obj. */
  428.     DB_LOCK_PUT_READ=7,        /* Release locker's read locks. */
  429.     DB_LOCK_TIMEOUT=8,        /* Force a txn to timeout. */
  430.     DB_LOCK_TRADE=9,        /* Trade locker ids on a lock. */
  431.     DB_LOCK_UPGRADE_WRITE=10    /* Upgrade writes for dirty reads. */
  432. } db_lockop_t;
  433.  
  434. /*
  435.  * Status of a lock.
  436.  */
  437. typedef enum  {
  438.     DB_LSTAT_ABORTED=1,        /* Lock belongs to an aborted txn. */
  439.     DB_LSTAT_EXPIRED=2,        /* Lock has expired. */
  440.     DB_LSTAT_FREE=3,        /* Lock is unallocated. */
  441.     DB_LSTAT_HELD=4,        /* Lock is currently held. */
  442.     DB_LSTAT_NOTEXIST=5,        /* Object on which lock was waiting
  443.                      * was removed */
  444.     DB_LSTAT_PENDING=6,        /* Lock was waiting and has been
  445.                      * promoted; waiting for the owner
  446.                      * to run and upgrade it to held. */
  447.     DB_LSTAT_WAITING=7        /* Lock is on the wait queue. */
  448. }db_status_t;
  449.  
  450. /* Lock statistics structure. */
  451. struct __db_lock_stat {
  452.     u_int32_t st_id;        /* Last allocated locker ID. */
  453.     u_int32_t st_cur_maxid;        /* Current maximum unused ID. */
  454.     u_int32_t st_maxlocks;        /* Maximum number of locks in table. */
  455.     u_int32_t st_maxlockers;    /* Maximum num of lockers in table. */
  456.     u_int32_t st_maxobjects;    /* Maximum num of objects in table. */
  457.     int      st_nmodes;        /* Number of lock modes. */
  458.     u_int32_t st_nlocks;        /* Current number of locks. */
  459.     u_int32_t st_maxnlocks;        /* Maximum number of locks so far. */
  460.     u_int32_t st_nlockers;        /* Current number of lockers. */
  461.     u_int32_t st_maxnlockers;    /* Maximum number of lockers so far. */
  462.     u_int32_t st_nobjects;        /* Current number of objects. */
  463.     u_int32_t st_maxnobjects;    /* Maximum number of objects so far. */
  464.     u_int32_t st_nconflicts;    /* Number of lock conflicts. */
  465.     u_int32_t st_nrequests;        /* Number of lock gets. */
  466.     u_int32_t st_nreleases;        /* Number of lock puts. */
  467.     u_int32_t st_nnowaits;        /* Number of requests that would have
  468.                        waited, but NOWAIT was set. */
  469.     u_int32_t st_ndeadlocks;    /* Number of lock deadlocks. */
  470.     db_timeout_t st_locktimeout;    /* Lock timeout. */
  471.     u_int32_t st_nlocktimeouts;    /* Number of lock timeouts. */
  472.     db_timeout_t st_txntimeout;    /* Transaction timeout. */
  473.     u_int32_t st_ntxntimeouts;    /* Number of transaction timeouts. */
  474.     u_int32_t st_region_wait;    /* Region lock granted after wait. */
  475.     u_int32_t st_region_nowait;    /* Region lock granted without wait. */
  476.     roff_t      st_regsize;        /* Region size. */
  477. };
  478.  
  479. /*
  480.  * DB_LOCK_ILOCK --
  481.  *    Internal DB access method lock.
  482.  */
  483. struct __db_ilock {
  484.     db_pgno_t pgno;            /* Page being locked. */
  485.     u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
  486. #define    DB_HANDLE_LOCK    1
  487. #define    DB_RECORD_LOCK    2
  488. #define    DB_PAGE_LOCK    3
  489.     u_int32_t type;            /* Type of lock. */
  490. };
  491.  
  492. /*
  493.  * DB_LOCK --
  494.  *    The structure is allocated by the caller and filled in during a
  495.  *    lock_get request (or a lock_vec/DB_LOCK_GET).
  496.  */
  497. struct __db_lock_u {
  498.     roff_t        off;        /* Offset of the lock in the region */
  499.     u_int32_t    ndx;        /* Index of the object referenced by
  500.                      * this lock; used for locking. */
  501.     u_int32_t    gen;        /* Generation number of this lock. */
  502.     db_lockmode_t    mode;        /* mode of this lock. */
  503. };
  504.  
  505. /* Lock request structure. */
  506. struct __db_lockreq {
  507.     db_lockop_t     op;        /* Operation. */
  508.     db_lockmode_t     mode;        /* Requested mode. */
  509.     db_timeout_t     timeout;    /* Time to expire lock. */
  510.     DBT        *obj;        /* Object being locked. */
  511.     DB_LOCK         lock;        /* Lock returned. */
  512. };
  513.  
  514. /*******************************************************
  515.  * Logging.
  516.  *******************************************************/
  517. #define    DB_LOGVERSION    10        /* Current log version. */
  518. #define    DB_LOGOLDVER    10        /* Oldest log version supported. */
  519. #define    DB_LOGMAGIC    0x040988
  520.  
  521. /* Flag values for DB_ENV->log_archive(). */
  522. #define    DB_ARCH_ABS    0x001        /* Absolute pathnames. */
  523. #define    DB_ARCH_DATA    0x002        /* Data files. */
  524. #define    DB_ARCH_LOG    0x004        /* Log files. */
  525. #define    DB_ARCH_REMOVE    0x008    /* Remove log files. */
  526.  
  527. /* Flag values for DB_ENV->log_put(). */
  528. #define    DB_FLUSH        0x001    /* Flush data to disk (public). */
  529. #define    DB_LOG_CHKPNT        0x002    /* Flush supports a checkpoint */
  530. #define    DB_LOG_COMMIT        0x004    /* Flush supports a commit */
  531. #define    DB_LOG_NOCOPY        0x008    /* Don't copy data */
  532. #define    DB_LOG_NOT_DURABLE    0x010    /* Do not log; keep in memory */
  533. #define    DB_LOG_PERM        0x020    /* Flag record with REP_PERMANENT */
  534. #define    DB_LOG_RESEND        0x040    /* Resent log record */
  535. #define    DB_LOG_WRNOSYNC        0x080    /* Write, don't sync log_put */
  536.  
  537. /*
  538.  * A DB_LSN has two parts, a fileid which identifies a specific file, and an
  539.  * offset within that file.  The fileid is an unsigned 4-byte quantity that
  540.  * uniquely identifies a file within the log directory -- currently a simple
  541.  * counter inside the log.  The offset is also an unsigned 4-byte value.  The
  542.  * log manager guarantees the offset is never more than 4 bytes by switching
  543.  * to a new log file before the maximum length imposed by an unsigned 4-byte
  544.  * offset is reached.
  545.  */
  546. struct __db_lsn {
  547.     u_int32_t    file;        /* File ID. */
  548.     u_int32_t    offset;        /* File offset. */
  549. };
  550.  
  551. /*
  552.  * Application-specified log record types start at DB_user_BEGIN, and must not
  553.  * equal or exceed DB_debug_FLAG.
  554.  *
  555.  * DB_debug_FLAG is the high-bit of the u_int32_t that specifies a log record
  556.  * type.  If the flag is set, it's a log record that was logged for debugging
  557.  * purposes only, even if it reflects a database change -- the change was part
  558.  * of a non-durable transaction.
  559.  */
  560. #define    DB_user_BEGIN        10000
  561. #define    DB_debug_FLAG        0x80000000
  562.  
  563. /*
  564.  * DB_LOGC --
  565.  *    Log cursor.
  566.  */
  567. struct __db_log_cursor {
  568.     DB_ENV     *dbenv;        /* Enclosing dbenv. */
  569.  
  570.     DB_FH     *c_fhp;        /* File handle. */
  571.     DB_LSN      c_lsn;        /* Cursor: LSN */
  572.     u_int32_t c_len;        /* Cursor: record length */
  573.     u_int32_t c_prev;        /* Cursor: previous record's offset */
  574.  
  575.     DBT      c_dbt;        /* Return DBT. */
  576.  
  577. #define    DB_LOGC_BUF_SIZE    (32 * 1024)
  578.     u_int8_t *bp;            /* Allocated read buffer. */
  579.     u_int32_t bp_size;        /* Read buffer length in bytes. */
  580.     u_int32_t bp_rlen;        /* Read buffer valid data length. */
  581.     DB_LSN      bp_lsn;        /* Read buffer first byte LSN. */
  582.  
  583.     u_int32_t bp_maxrec;        /* Max record length in the log file. */
  584.  
  585.                     /* Methods. */
  586.     int (*close) __P((DB_LOGC *, u_int32_t));
  587.     int (*get) __P((DB_LOGC *, DB_LSN *, DBT *, u_int32_t));
  588.  
  589. #define    DB_LOG_DISK        0x01    /* Log record came from disk. */
  590. #define    DB_LOG_LOCKED        0x02    /* Log region already locked */
  591. #define    DB_LOG_SILENT_ERR    0x04    /* Turn-off error messages. */
  592.     u_int32_t flags;
  593. };
  594.  
  595. /* Log statistics structure. */
  596. struct __db_log_stat {
  597.     u_int32_t st_magic;        /* Log file magic number. */
  598.     u_int32_t st_version;        /* Log file version number. */
  599.     int      st_mode;            /* Log file mode. */
  600.     u_int32_t st_lg_bsize;        /* Log buffer size. */
  601.     u_int32_t st_lg_size;        /* Log file size. */
  602.     u_int32_t st_w_bytes;        /* Bytes to log. */
  603.     u_int32_t st_w_mbytes;        /* Megabytes to log. */
  604.     u_int32_t st_wc_bytes;        /* Bytes to log since checkpoint. */
  605.     u_int32_t st_wc_mbytes;        /* Megabytes to log since checkpoint. */
  606.     u_int32_t st_wcount;        /* Total writes to the log. */
  607.     u_int32_t st_wcount_fill;    /* Overflow writes to the log. */
  608.     u_int32_t st_scount;        /* Total syncs to the log. */
  609.     u_int32_t st_region_wait;    /* Region lock granted after wait. */
  610.     u_int32_t st_region_nowait;    /* Region lock granted without wait. */
  611.     u_int32_t st_cur_file;        /* Current log file number. */
  612.     u_int32_t st_cur_offset;    /* Current log file offset. */
  613.     u_int32_t st_disk_file;        /* Known on disk log file number. */
  614.     u_int32_t st_disk_offset;    /* Known on disk log file offset. */
  615.     roff_t      st_regsize;        /* Region size. */
  616.     u_int32_t st_maxcommitperflush;    /* Max number of commits in a flush. */
  617.     u_int32_t st_mincommitperflush;    /* Min number of commits in a flush. */
  618. };
  619.  
  620. /*
  621.  * We need to record the first log record of a transaction.
  622.  * For user defined logging this macro returns the place to
  623.  * put that information, if it is need in rlsnp, otherwise it
  624.  * leaves it unchanged.
  625.  */
  626. #define    DB_SET_BEGIN_LSNP(txn, rlsnp)    ((txn)->set_begin_lsnp(txn, rlsnp))
  627.  
  628. /*******************************************************
  629.  * Shared buffer cache (mpool).
  630.  *******************************************************/
  631. /* Flag values for DB_MPOOLFILE->get. */
  632. #define    DB_MPOOL_CREATE        0x001    /* Create a page. */
  633. #define    DB_MPOOL_LAST        0x002    /* Return the last page. */
  634. #define    DB_MPOOL_NEW        0x004    /* Create a new page. */
  635.  
  636. /* Flag values for DB_MPOOLFILE->put, DB_MPOOLFILE->set. */
  637. #define    DB_MPOOL_CLEAN        0x001    /* Page is not modified. */
  638. #define    DB_MPOOL_DIRTY        0x002    /* Page is modified. */
  639. #define    DB_MPOOL_DISCARD    0x004    /* Don't cache the page. */
  640. #define    DB_MPOOL_FREE        0x008    /* Free page if present. */
  641.  
  642. /* Flags values for DB_MPOOLFILE->set_flags. */
  643. #define    DB_MPOOL_NOFILE        0x001    /* Never open a backing file. */
  644. #define    DB_MPOOL_UNLINK        0x002    /* Unlink the file on last close. */
  645.  
  646. /* Priority values for DB_MPOOLFILE->set_priority. */
  647. typedef enum {
  648.     DB_PRIORITY_VERY_LOW=1,
  649.     DB_PRIORITY_LOW=2,
  650.     DB_PRIORITY_DEFAULT=3,
  651.     DB_PRIORITY_HIGH=4,
  652.     DB_PRIORITY_VERY_HIGH=5
  653. } DB_CACHE_PRIORITY;
  654.  
  655. /* Per-process DB_MPOOLFILE information. */
  656. struct __db_mpoolfile {
  657.     DB_FH      *fhp;            /* Underlying file handle. */
  658.  
  659.     /*
  660.      * !!!
  661.      * The ref, pinref and q fields are protected by the region lock.
  662.      */
  663.     u_int32_t  ref;            /* Reference count. */
  664.  
  665.     u_int32_t pinref;        /* Pinned block reference count. */
  666.  
  667.     /*
  668.      * !!!
  669.      * Explicit representations of structures from queue.h.
  670.      * TAILQ_ENTRY(__db_mpoolfile) q;
  671.      */
  672.     struct {
  673.         struct __db_mpoolfile *tqe_next;
  674.         struct __db_mpoolfile **tqe_prev;
  675.     } q;                /* Linked list of DB_MPOOLFILE's. */
  676.  
  677.     /*
  678.      * !!!
  679.      * The rest of the fields (with the exception of the MP_FLUSH flag)
  680.      * are not thread-protected, even when they may be modified at any
  681.      * time by the application.  The reason is the DB_MPOOLFILE handle
  682.      * is single-threaded from the viewpoint of the application, and so
  683.      * the only fields needing to be thread-protected are those accessed
  684.      * by checkpoint or sync threads when using DB_MPOOLFILE structures
  685.      * to flush buffers from the cache.
  686.      */
  687.     DB_ENV           *dbenv;        /* Overlying DB_ENV. */
  688.     MPOOLFILE      *mfp;        /* Underlying MPOOLFILE. */
  689.  
  690.     u_int32_t    clear_len;    /* Cleared length on created pages. */
  691.     u_int8_t            /* Unique file ID. */
  692.             fileid[DB_FILE_ID_LEN];
  693.     int        ftype;        /* File type. */
  694.     int32_t        lsn_offset;    /* LSN offset in page. */
  695.     u_int32_t    gbytes, bytes;    /* Maximum file size. */
  696.     DBT           *pgcookie;    /* Byte-string passed to pgin/pgout. */
  697.     DB_CACHE_PRIORITY        /* Cache priority. */
  698.             priority;
  699.  
  700.     void           *addr;        /* Address of mmap'd region. */
  701.     size_t        len;        /* Length of mmap'd region. */
  702.  
  703.     u_int32_t    config_flags;    /* Flags to DB_MPOOLFILE->set_flags. */
  704.  
  705.                     /* Methods. */
  706.     int (*close) __P((DB_MPOOLFILE *, u_int32_t));
  707.     int (*get) __P((DB_MPOOLFILE *, db_pgno_t *, u_int32_t, void *));
  708.     int (*open) __P((DB_MPOOLFILE *, const char *, u_int32_t, int, size_t));
  709.     int (*put) __P((DB_MPOOLFILE *, void *, u_int32_t));
  710.     int (*set) __P((DB_MPOOLFILE *, void *, u_int32_t));
  711.     int (*get_clear_len) __P((DB_MPOOLFILE *, u_int32_t *));
  712.     int (*set_clear_len) __P((DB_MPOOLFILE *, u_int32_t));
  713.     int (*get_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
  714.     int (*set_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
  715.     int (*get_flags) __P((DB_MPOOLFILE *, u_int32_t *));
  716.     int (*set_flags) __P((DB_MPOOLFILE *, u_int32_t, int));
  717.     int (*get_ftype) __P((DB_MPOOLFILE *, int *));
  718.     int (*set_ftype) __P((DB_MPOOLFILE *, int));
  719.     int (*get_lsn_offset) __P((DB_MPOOLFILE *, int32_t *));
  720.     int (*set_lsn_offset) __P((DB_MPOOLFILE *, int32_t));
  721.     int (*get_maxsize) __P((DB_MPOOLFILE *, u_int32_t *, u_int32_t *));
  722.     int (*set_maxsize) __P((DB_MPOOLFILE *, u_int32_t, u_int32_t));
  723.     int (*get_pgcookie) __P((DB_MPOOLFILE *, DBT *));
  724.     int (*set_pgcookie) __P((DB_MPOOLFILE *, DBT *));
  725.     int (*get_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY *));
  726.     int (*set_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY));
  727.     int (*sync) __P((DB_MPOOLFILE *));
  728.  
  729.     /*
  730.      * MP_FILEID_SET, MP_OPEN_CALLED and MP_READONLY do not need to be
  731.      * thread protected because they are initialized before the file is
  732.      * linked onto the per-process lists, and never modified.
  733.      *
  734.      * MP_FLUSH is thread protected because it is potentially read/set by
  735.      * multiple threads of control.
  736.      */
  737. #define    MP_FILEID_SET    0x001        /* Application supplied a file ID. */
  738. #define    MP_FLUSH    0x002        /* Was opened to flush a buffer. */
  739. #define    MP_OPEN_CALLED    0x004        /* File opened. */
  740. #define    MP_READONLY    0x008        /* File is readonly. */
  741.     u_int32_t  flags;
  742. };
  743.  
  744. /* Mpool statistics structure. */
  745. struct __db_mpool_stat {
  746.     u_int32_t st_gbytes;        /* Total cache size: GB. */
  747.     u_int32_t st_bytes;        /* Total cache size: B. */
  748.     u_int32_t st_ncache;        /* Number of caches. */
  749.     roff_t      st_regsize;        /* Region size. */
  750.     size_t      st_mmapsize;        /* Maximum file size for mmap. */
  751.     int      st_maxopenfd;        /* Maximum number of open fd's. */
  752.     int      st_maxwrite;        /* Maximum buffers to write. */
  753.     int      st_maxwrite_sleep;    /* Sleep after writing max buffers. */
  754.     u_int32_t st_map;        /* Pages from mapped files. */
  755.     u_int32_t st_cache_hit;        /* Pages found in the cache. */
  756.     u_int32_t st_cache_miss;    /* Pages not found in the cache. */
  757.     u_int32_t st_page_create;    /* Pages created in the cache. */
  758.     u_int32_t st_page_in;        /* Pages read in. */
  759.     u_int32_t st_page_out;        /* Pages written out. */
  760.     u_int32_t st_ro_evict;        /* Clean pages forced from the cache. */
  761.     u_int32_t st_rw_evict;        /* Dirty pages forced from the cache. */
  762.     u_int32_t st_page_trickle;    /* Pages written by memp_trickle. */
  763.     u_int32_t st_pages;        /* Total number of pages. */
  764.     u_int32_t st_page_clean;    /* Clean pages. */
  765.     u_int32_t st_page_dirty;    /* Dirty pages. */
  766.     u_int32_t st_hash_buckets;    /* Number of hash buckets. */
  767.     u_int32_t st_hash_searches;    /* Total hash chain searches. */
  768.     u_int32_t st_hash_longest;    /* Longest hash chain searched. */
  769.     u_int32_t st_hash_examined;    /* Total hash entries searched. */
  770.     u_int32_t st_hash_nowait;    /* Hash lock granted with nowait. */
  771.     u_int32_t st_hash_wait;        /* Hash lock granted after wait. */
  772.     u_int32_t st_hash_max_wait;    /* Max hash lock granted after wait. */
  773.     u_int32_t st_region_nowait;    /* Region lock granted with nowait. */
  774.     u_int32_t st_region_wait;    /* Region lock granted after wait. */
  775.     u_int32_t st_alloc;        /* Number of page allocations. */
  776.     u_int32_t st_alloc_buckets;    /* Buckets checked during allocation. */
  777.     u_int32_t st_alloc_max_buckets;    /* Max checked during allocation. */
  778.     u_int32_t st_alloc_pages;    /* Pages checked during allocation. */
  779.     u_int32_t st_alloc_max_pages;    /* Max checked during allocation. */
  780. };
  781.  
  782. /* Mpool file statistics structure. */
  783. struct __db_mpool_fstat {
  784.     char *file_name;        /* File name. */
  785.     u_int32_t st_pagesize;        /* Page size. */
  786.     u_int32_t st_map;        /* Pages from mapped files. */
  787.     u_int32_t st_cache_hit;        /* Pages found in the cache. */
  788.     u_int32_t st_cache_miss;    /* Pages not found in the cache. */
  789.     u_int32_t st_page_create;    /* Pages created in the cache. */
  790.     u_int32_t st_page_in;        /* Pages read in. */
  791.     u_int32_t st_page_out;        /* Pages written out. */
  792. };
  793.  
  794. /*******************************************************
  795.  * Transactions and recovery.
  796.  *******************************************************/
  797. #define    DB_TXNVERSION    1
  798.  
  799. typedef enum {
  800.     DB_TXN_ABORT=0,            /* Public. */
  801.     DB_TXN_APPLY=1,            /* Public. */
  802.     DB_TXN_BACKWARD_ALLOC=2,    /* Internal. */
  803.     DB_TXN_BACKWARD_ROLL=3,        /* Public. */
  804.     DB_TXN_FORWARD_ROLL=4,        /* Public. */
  805.     DB_TXN_OPENFILES=5,        /* Internal. */
  806.     DB_TXN_POPENFILES=6,        /* Internal. */
  807.     DB_TXN_PRINT=7            /* Public. */
  808. } db_recops;
  809.  
  810. /*
  811.  * BACKWARD_ALLOC is used during the forward pass to pick up any aborted
  812.  * allocations for files that were created during the forward pass.
  813.  * The main difference between _ALLOC and _ROLL is that the entry for
  814.  * the file not exist during the rollforward pass.
  815.  */
  816. #define    DB_UNDO(op)    ((op) == DB_TXN_ABORT ||            \
  817.         (op) == DB_TXN_BACKWARD_ROLL || (op) == DB_TXN_BACKWARD_ALLOC)
  818. #define    DB_REDO(op)    ((op) == DB_TXN_FORWARD_ROLL || (op) == DB_TXN_APPLY)
  819.  
  820. struct __db_txn {
  821.     DB_TXNMGR    *mgrp;        /* Pointer to transaction manager. */
  822.     DB_TXN        *parent;    /* Pointer to transaction's parent. */
  823.     DB_LSN        last_lsn;    /* Lsn of last log write. */
  824.     u_int32_t    txnid;        /* Unique transaction id. */
  825.     u_int32_t    tid;        /* Thread id for use in MT XA. */
  826.     roff_t        off;        /* Detail structure within region. */
  827.     db_timeout_t    lock_timeout;    /* Timeout for locks for this txn. */
  828.     db_timeout_t    expire;        /* Time this txn expires. */
  829.     void        *txn_list;    /* Undo information for parent. */
  830.  
  831.     /*
  832.      * !!!
  833.      * Explicit representations of structures from queue.h.
  834.      * TAILQ_ENTRY(__db_txn) links;
  835.      * TAILQ_ENTRY(__db_txn) xalinks;
  836.      */
  837.     struct {
  838.         struct __db_txn *tqe_next;
  839.         struct __db_txn **tqe_prev;
  840.     } links;            /* Links transactions off manager. */
  841.     struct {
  842.         struct __db_txn *tqe_next;
  843.         struct __db_txn **tqe_prev;
  844.     } xalinks;            /* Links active XA transactions. */
  845.  
  846.     /*
  847.      * !!!
  848.      * Explicit representations of structures from queue.h.
  849.      * TAILQ_HEAD(__events, __txn_event) events;
  850.      */
  851.     struct {
  852.         struct __txn_event *tqh_first;
  853.         struct __txn_event **tqh_last;
  854.     } events;
  855.  
  856.     /*
  857.      * !!!
  858.      * Explicit representations of structures from queue.h.
  859.      * STAILQ_HEAD(__logrec, __txn_logrec) logs;
  860.      */
  861.     struct {
  862.         struct __txn_logrec *stqh_first;
  863.         struct __txn_logrec **stqh_last;
  864.     } logs;                /* Links deferred events. */
  865.  
  866.     /*
  867.      * !!!
  868.      * Explicit representations of structures from queue.h.
  869.      * TAILQ_HEAD(__kids, __db_txn) kids;
  870.      */
  871.     struct __kids {
  872.         struct __db_txn *tqh_first;
  873.         struct __db_txn **tqh_last;
  874.     } kids;
  875.  
  876.     /*
  877.      * !!!
  878.      * Explicit representations of structures from queue.h.
  879.      * TAILQ_ENTRY(__db_txn) klinks;
  880.      */
  881.     struct {
  882.         struct __db_txn *tqe_next;
  883.         struct __db_txn **tqe_prev;
  884.     } klinks;
  885.  
  886.     void    *api_internal;        /* C++ API private. */
  887.     void    *xml_internal;        /* XML API private. */
  888.  
  889.     u_int32_t    cursors;    /* Number of cursors open for txn */
  890.  
  891.                     /* Methods. */
  892.     int      (*abort) __P((DB_TXN *));
  893.     int      (*commit) __P((DB_TXN *, u_int32_t));
  894.     int      (*discard) __P((DB_TXN *, u_int32_t));
  895.     u_int32_t (*id) __P((DB_TXN *));
  896.     int      (*prepare) __P((DB_TXN *, u_int8_t *));
  897.     void      (*set_begin_lsnp) __P((DB_TXN *txn, DB_LSN **));
  898.     int      (*set_timeout) __P((DB_TXN *, db_timeout_t, u_int32_t));
  899.  
  900. #define    TXN_CHILDCOMMIT    0x001        /* Transaction that has committed. */
  901. #define    TXN_COMPENSATE    0x002        /* Compensating transaction. */
  902. #define    TXN_DEADLOCK    0x004        /* Transaction has deadlocked. */
  903. #define    TXN_DEGREE_2    0x008        /* Has degree 2 isolation. */
  904. #define    TXN_DIRTY_READ    0x010        /* Transaction does dirty reads. */
  905. #define    TXN_LOCKTIMEOUT    0x020        /* Transaction has a lock timeout. */
  906. #define    TXN_MALLOC    0x040        /* Structure allocated by TXN system. */
  907. #define    TXN_NOSYNC    0x080        /* Do not sync on prepare and commit. */
  908. #define    TXN_NOWAIT    0x100        /* Do not wait on locks. */
  909. #define    TXN_RESTORED    0x200        /* Transaction has been restored. */
  910. #define    TXN_SYNC    0x400        /* Sync on prepare and commit. */
  911.     u_int32_t    flags;
  912. };
  913.  
  914. /*
  915.  * Structure used for two phase commit interface.  Berkeley DB support for two
  916.  * phase commit is compatible with the X/open XA interface.
  917.  *
  918.  * The XA #define XIDDATASIZE defines the size of a global transaction ID.  We
  919.  * have our own version here (for name space reasons) which must have the same
  920.  * value.
  921.  */
  922. #define    DB_XIDDATASIZE    128
  923. struct __db_preplist {
  924.     DB_TXN    *txn;
  925.     u_int8_t gid[DB_XIDDATASIZE];
  926. };
  927.  
  928. /* Transaction statistics structure. */
  929. struct __db_txn_active {
  930.     u_int32_t txnid;        /* Transaction ID */
  931.     u_int32_t parentid;        /* Transaction ID of parent */
  932.     DB_LSN      lsn;            /* LSN when transaction began */
  933.     u_int32_t xa_status;        /* XA status */
  934.     u_int8_t  xid[DB_XIDDATASIZE];    /* XA global transaction ID */
  935. };
  936.  
  937. struct __db_txn_stat {
  938.     DB_LSN      st_last_ckp;        /* lsn of the last checkpoint */
  939.     time_t      st_time_ckp;        /* time of last checkpoint */
  940.     u_int32_t st_last_txnid;    /* last transaction id given out */
  941.     u_int32_t st_maxtxns;        /* maximum txns possible */
  942.     u_int32_t st_naborts;        /* number of aborted transactions */
  943.     u_int32_t st_nbegins;        /* number of begun transactions */
  944.     u_int32_t st_ncommits;        /* number of committed transactions */
  945.     u_int32_t st_nactive;        /* number of active transactions */
  946.     u_int32_t st_nrestores;        /* number of restored transactions
  947.                        after recovery. */
  948.     u_int32_t st_maxnactive;    /* maximum active transactions */
  949.     DB_TXN_ACTIVE *st_txnarray;    /* array of active transactions */
  950.     u_int32_t st_region_wait;    /* Region lock granted after wait. */
  951.     u_int32_t st_region_nowait;    /* Region lock granted without wait. */
  952.     roff_t      st_regsize;        /* Region size. */
  953. };
  954.  
  955. /*******************************************************
  956.  * Replication.
  957.  *******************************************************/
  958. /* Special, out-of-band environment IDs. */
  959. #define    DB_EID_BROADCAST    -1
  960. #define    DB_EID_INVALID        -2
  961.  
  962. /* rep_start flags values */
  963. #define    DB_REP_CLIENT        0x001
  964. #define    DB_REP_MASTER        0x002
  965.  
  966. /* Replication statistics. */
  967. struct __db_rep_stat {
  968.     /* !!!
  969.      * Many replication statistics fields cannot be protected by a mutex
  970.      * without an unacceptable performance penalty, since most message
  971.      * processing is done without the need to hold a region-wide lock.
  972.      * Fields whose comments end with a '+' may be updated without holding
  973.      * the replication or log mutexes (as appropriate), and thus may be
  974.      * off somewhat (or, on unreasonable architectures under unlucky
  975.      * circumstances, garbaged).
  976.      */
  977.     u_int32_t st_status;        /* Current replication status. */
  978.     DB_LSN st_next_lsn;        /* Next LSN to use or expect. */
  979.     DB_LSN st_waiting_lsn;        /* LSN we're awaiting, if any. */
  980.     db_pgno_t st_next_pg;        /* Next pg we expect. */
  981.     db_pgno_t st_waiting_pg;    /* pg we're awaiting, if any. */
  982.  
  983.     u_int32_t st_dupmasters;    /* # of times a duplicate master
  984.                        condition was detected.+ */
  985.     int st_env_id;            /* Current environment ID. */
  986.     int st_env_priority;        /* Current environment priority. */
  987.     u_int32_t st_gen;        /* Current generation number. */
  988.     u_int32_t st_egen;        /* Current election gen number. */
  989.     u_int32_t st_log_duplicated;    /* Log records received multiply.+ */
  990.     u_int32_t st_log_queued;    /* Log records currently queued.+ */
  991.     u_int32_t st_log_queued_max;    /* Max. log records queued at once.+ */
  992.     u_int32_t st_log_queued_total;    /* Total # of log recs. ever queued.+ */
  993.     u_int32_t st_log_records;    /* Log records received and put.+ */
  994.     u_int32_t st_log_requested;    /* Log recs. missed and requested.+ */
  995.     int st_master;            /* Env. ID of the current master. */
  996.     u_int32_t st_master_changes;    /* # of times we've switched masters. */
  997.     u_int32_t st_msgs_badgen;    /* Messages with a bad generation #.+ */
  998.     u_int32_t st_msgs_processed;    /* Messages received and processed.+ */
  999.     u_int32_t st_msgs_recover;    /* Messages ignored because this site
  1000.                        was a client in recovery.+ */
  1001.     u_int32_t st_msgs_send_failures;/* # of failed message sends.+ */
  1002.     u_int32_t st_msgs_sent;        /* # of successful message sends.+ */
  1003.     u_int32_t st_newsites;        /* # of NEWSITE msgs. received.+ */
  1004.     int st_nsites;            /* Current number of sites we will
  1005.                        assume during elections. */
  1006.     u_int32_t st_nthrottles;    /* # of times we were throttled. */
  1007.     u_int32_t st_outdated;        /* # of times we detected and returned
  1008.                        an OUTDATED condition.+ */
  1009.     u_int32_t st_pg_duplicated;    /* Pages received multiply.+ */
  1010.     u_int32_t st_pg_records;    /* Pages received and stored.+ */
  1011.     u_int32_t st_pg_requested;    /* Pages missed and requested.+ */
  1012.     u_int32_t st_startup_complete;    /* Site completed client sync-up. */
  1013.     u_int32_t st_txns_applied;    /* # of transactions applied.+ */
  1014.  
  1015.     /* Elections generally. */
  1016.     u_int32_t st_elections;        /* # of elections held.+ */
  1017.     u_int32_t st_elections_won;    /* # of elections won by this site.+ */
  1018.  
  1019.     /* Statistics about an in-progress election. */
  1020.     int st_election_cur_winner;    /* Current front-runner. */
  1021.     u_int32_t st_election_gen;    /* Election generation number. */
  1022.     DB_LSN st_election_lsn;        /* Max. LSN of current winner. */
  1023.     int st_election_nsites;        /* # of "registered voters". */
  1024.     int st_election_nvotes;        /* # of "registered voters" needed. */
  1025.     int st_election_priority;    /* Current election priority. */
  1026.     int st_election_status;        /* Current election status. */
  1027.     u_int32_t st_election_tiebreaker;/* Election tiebreaker value. */
  1028.     int st_election_votes;        /* Votes received in this round. */
  1029. };
  1030. /*
  1031.  * The storage record for a sequence.
  1032.  */
  1033. struct __db_seq_record {
  1034.     u_int32_t    seq_version;    /* Version size/number. */
  1035. #define    DB_SEQ_DEC        0x00000001    /* Decrement sequence. */
  1036. #define    DB_SEQ_INC        0x00000002    /* Increment sequence. */
  1037. #define    DB_SEQ_RANGE_SET    0x00000004    /* Range set (internal). */
  1038. #define    DB_SEQ_WRAP        0x00000008    /* Wrap sequence at min/max. */
  1039.     u_int32_t    flags;        /* Flags. */
  1040.     db_seq_t    seq_value;    /* Current value. */
  1041.     db_seq_t    seq_max;    /* Max permitted. */
  1042.     db_seq_t    seq_min;    /* Min permitted. */
  1043. };
  1044.  
  1045. /*
  1046.  * Handle for a sequence object.
  1047.  */
  1048. struct __db_sequence {
  1049.     DB        *seq_dbp;    /* DB handle for this sequence. */
  1050.     DB_MUTEX    *seq_mutexp;    /* Mutex if sequence is threaded. */
  1051.     DB_SEQ_RECORD    *seq_rp;    /* Pointer to current data. */
  1052.     DB_SEQ_RECORD    seq_record;    /* Data from DB_SEQUENCE. */
  1053.     int32_t        seq_cache_size; /* Number of values cached. */
  1054.     db_seq_t    seq_last_value;    /* Last value cached. */
  1055.     DBT        seq_key;    /* DBT pointing to sequence key. */
  1056.     DBT        seq_data;    /* DBT pointing to seq_record. */
  1057.  
  1058.     /* API-private structure: used by C++ and Java. */
  1059.     void        *api_internal;
  1060.  
  1061.     int        (*close) __P((DB_SEQUENCE *, u_int32_t));
  1062.     int        (*get) __P((DB_SEQUENCE *,
  1063.                   DB_TXN *, int32_t, db_seq_t *, u_int32_t));
  1064.     int        (*get_cachesize) __P((DB_SEQUENCE *, int32_t *));
  1065.     int        (*get_db) __P((DB_SEQUENCE *, DB **));
  1066.     int        (*get_flags) __P((DB_SEQUENCE *, u_int32_t *));
  1067.     int        (*get_key) __P((DB_SEQUENCE *, DBT *));
  1068.     int        (*get_range) __P((DB_SEQUENCE *,
  1069.                  db_seq_t *, db_seq_t *));
  1070.     int        (*initial_value) __P((DB_SEQUENCE *, db_seq_t));
  1071.     int        (*open) __P((DB_SEQUENCE *,
  1072.                 DB_TXN *, DBT *, u_int32_t));
  1073.     int        (*remove) __P((DB_SEQUENCE *, DB_TXN *, u_int32_t));
  1074.     int        (*set_cachesize) __P((DB_SEQUENCE *, int32_t));
  1075.     int        (*set_flags) __P((DB_SEQUENCE *, u_int32_t));
  1076.     int        (*set_range) __P((DB_SEQUENCE *, db_seq_t, db_seq_t));
  1077.     int        (*stat) __P((DB_SEQUENCE *,
  1078.                 DB_SEQUENCE_STAT **, u_int32_t));
  1079.     int        (*stat_print) __P((DB_SEQUENCE *, u_int32_t));
  1080. };
  1081.  
  1082. struct __db_seq_stat {
  1083.     u_int32_t st_wait;      /* Sequence lock granted without wait. */
  1084.     u_int32_t st_nowait;      /* Sequence lock granted after wait. */
  1085.     db_seq_t  st_current;      /* Current value in db. */
  1086.     db_seq_t  st_value;      /* Current cached value. */
  1087.     db_seq_t  st_last_value;  /* Last cached value. */
  1088.     db_seq_t  st_min;      /* Minimum value. */
  1089.     db_seq_t  st_max;      /* Maximum value. */
  1090.     int32_t   st_cache_size;  /* Cache size. */
  1091.     u_int32_t st_flags;      /* Flag value. */
  1092. };
  1093.  
  1094. /*******************************************************
  1095.  * Access methods.
  1096.  *******************************************************/
  1097. typedef enum {
  1098.     DB_BTREE=1,
  1099.     DB_HASH=2,
  1100.     DB_RECNO=3,
  1101.     DB_QUEUE=4,
  1102.     DB_UNKNOWN=5            /* Figure it out on open. */
  1103. } DBTYPE;
  1104.  
  1105. #define    DB_RENAMEMAGIC    0x030800    /* File has been renamed. */
  1106.  
  1107. #define    DB_BTREEVERSION    9        /* Current btree version. */
  1108. #define    DB_BTREEOLDVER    8        /* Oldest btree version supported. */
  1109. #define    DB_BTREEMAGIC    0x053162
  1110.  
  1111. #define    DB_HASHVERSION    8        /* Current hash version. */
  1112. #define    DB_HASHOLDVER    7        /* Oldest hash version supported. */
  1113. #define    DB_HASHMAGIC    0x061561
  1114.  
  1115. #define    DB_QAMVERSION    4        /* Current queue version. */
  1116. #define    DB_QAMOLDVER    3        /* Oldest queue version supported. */
  1117. #define    DB_QAMMAGIC    0x042253
  1118.  
  1119. #define    DB_SEQUENCE_VERSION 1        /* Current sequence version. */
  1120.  
  1121. /*
  1122.  * DB access method and cursor operation values.  Each value is an operation
  1123.  * code to which additional bit flags are added.
  1124.  */
  1125. #define    DB_AFTER         1    /* c_put() */
  1126. #define    DB_APPEND         2    /* put() */
  1127. #define    DB_BEFORE         3    /* c_put() */
  1128. #define    DB_CACHED_COUNTS     4    /* stat() */
  1129. #define    DB_CONSUME         5    /* get() */
  1130. #define    DB_CONSUME_WAIT         6    /* get() */
  1131. #define    DB_CURRENT         7    /* c_get(), c_put(), DB_LOGC->get() */
  1132. #define    DB_FAST_STAT         8    /* stat() */
  1133. #define    DB_FIRST         9    /* c_get(), DB_LOGC->get() */
  1134. #define    DB_GET_BOTH        10    /* get(), c_get() */
  1135. #define    DB_GET_BOTHC        11    /* c_get() (internal) */
  1136. #define    DB_GET_BOTH_RANGE    12    /* get(), c_get() */
  1137. #define    DB_GET_RECNO        13    /* c_get() */
  1138. #define    DB_JOIN_ITEM        14    /* c_get(); do not do primary lookup */
  1139. #define    DB_KEYFIRST        15    /* c_put() */
  1140. #define    DB_KEYLAST        16    /* c_put() */
  1141. #define    DB_LAST            17    /* c_get(), DB_LOGC->get() */
  1142. #define    DB_NEXT            18    /* c_get(), DB_LOGC->get() */
  1143. #define    DB_NEXT_DUP        19    /* c_get() */
  1144. #define    DB_NEXT_NODUP        20    /* c_get() */
  1145. #define    DB_NODUPDATA        21    /* put(), c_put() */
  1146. #define    DB_NOOVERWRITE        22    /* put() */
  1147. #define    DB_NOSYNC        23    /* close() */
  1148. #define    DB_POSITION        24    /* c_dup() */
  1149. #define    DB_PREV            25    /* c_get(), DB_LOGC->get() */
  1150. #define    DB_PREV_NODUP        26    /* c_get(), DB_LOGC->get() */
  1151. #define    DB_RECORDCOUNT        27    /* stat() */
  1152. #define    DB_SET            28    /* c_get(), DB_LOGC->get() */
  1153. #define    DB_SET_LOCK_TIMEOUT    29    /* set_timout() */
  1154. #define    DB_SET_RANGE        30    /* c_get() */
  1155. #define    DB_SET_RECNO        31    /* get(), c_get() */
  1156. #define    DB_SET_TXN_NOW        32    /* set_timout() (internal) */
  1157. #define    DB_SET_TXN_TIMEOUT    33    /* set_timout() */
  1158. #define    DB_UPDATE_SECONDARY    34    /* c_get(), c_del() (internal) */
  1159. #define    DB_WRITECURSOR        35    /* cursor() */
  1160. #define    DB_WRITELOCK        36    /* cursor() (internal) */
  1161.  
  1162. /* This has to change when the max opcode hits 255. */
  1163. #define    DB_OPFLAGS_MASK    0x000000ff    /* Mask for operations flags. */
  1164.  
  1165. /*
  1166.  * Masks for flags that can be OR'd into DB access method and cursor
  1167.  * operation values.
  1168.  *
  1169.  *    DB_DIRTY_READ    0x04000000       Dirty Read. */
  1170. #define    DB_MULTIPLE    0x08000000    /* Return multiple data values. */
  1171. #define    DB_MULTIPLE_KEY    0x10000000    /* Return multiple data/key pairs. */
  1172. #define    DB_RMW        0x20000000    /* Acquire write flag immediately. */
  1173.  
  1174. /*
  1175.  * DB (user visible) error return codes.
  1176.  *
  1177.  * !!!
  1178.  * For source compatibility with DB 2.X deadlock return (EAGAIN), use the
  1179.  * following:
  1180.  *    #include <errno.h>
  1181.  *    #define DB_LOCK_DEADLOCK EAGAIN
  1182.  *
  1183.  * !!!
  1184.  * We don't want our error returns to conflict with other packages where
  1185.  * possible, so pick a base error value that's hopefully not common.  We
  1186.  * document that we own the error name space from -30,800 to -30,999.
  1187.  */
  1188. /* DB (public) error return codes. */
  1189. #define    DB_BUFFER_SMALL        (-30999)/* User memory too small for return. */
  1190. #define    DB_DONOTINDEX        (-30998)/* "Null" return from 2ndary callbk. */
  1191. #define    DB_KEYEMPTY        (-30997)/* Key/data deleted or never created. */
  1192. #define    DB_KEYEXIST        (-30996)/* The key/data pair already exists. */
  1193. #define    DB_LOCK_DEADLOCK    (-30995)/* Deadlock. */
  1194. #define    DB_LOCK_NOTGRANTED    (-30994)/* Lock unavailable. */
  1195. #define    DB_LOG_BUFFER_FULL    (-30993)/* In-memory log buffer full. */
  1196. #define    DB_NOSERVER        (-30992)/* Server panic return. */
  1197. #define    DB_NOSERVER_HOME    (-30991)/* Bad home sent to server. */
  1198. #define    DB_NOSERVER_ID        (-30990)/* Bad ID sent to server. */
  1199. #define    DB_NOTFOUND        (-30989)/* Key/data pair not found (EOF). */
  1200. #define    DB_OLD_VERSION        (-30988)/* Out-of-date version. */
  1201. #define    DB_PAGE_NOTFOUND    (-30987)/* Requested page not found. */
  1202. #define    DB_REP_DUPMASTER    (-30986)/* There are two masters. */
  1203. #define    DB_REP_HANDLE_DEAD    (-30985)/* Rolled back a commit. */
  1204. #define    DB_REP_HOLDELECTION    (-30984)/* Time to hold an election. */
  1205. #define    DB_REP_ISPERM        (-30983)/* Cached not written perm written.*/
  1206. #define    DB_REP_NEWMASTER    (-30982)/* We have learned of a new master. */
  1207. #define    DB_REP_NEWSITE        (-30981)/* New site entered system. */
  1208. #define    DB_REP_NOTPERM        (-30980)/* Permanent log record not written. */
  1209. #define    DB_REP_STARTUPDONE    (-30979)/* Client startup complete. */
  1210. #define    DB_REP_UNAVAIL        (-30978)/* Site cannot currently be reached. */
  1211. #define    DB_RUNRECOVERY        (-30977)/* Panic return. */
  1212. #define    DB_SECONDARY_BAD    (-30976)/* Secondary index corrupt. */
  1213. #define    DB_VERIFY_BAD        (-30975)/* Verify failed; bad format. */
  1214. #define    DB_VERSION_MISMATCH    (-30974)/* Environment version mismatch. */
  1215.  
  1216. /* DB (private) error return codes. */
  1217. #define    DB_ALREADY_ABORTED    (-30899)
  1218. #define    DB_DELETED        (-30898)/* Recovery file marked deleted. */
  1219. #define    DB_LOCK_NOTEXIST    (-30897)/* Object to lock is gone. */
  1220. #define    DB_NEEDSPLIT        (-30896)/* Page needs to be split. */
  1221. #define    DB_REP_EGENCHG        (-30895)/* Egen changed while in election. */
  1222. #define    DB_REP_LOGREADY        (-30894)/* Rep log ready for recovery. */
  1223. #define    DB_REP_PAGEDONE        (-30893)/* This page was already done. */
  1224. #define    DB_SURPRISE_KID        (-30892)/* Child commit where parent
  1225.                        didn't know it was a parent. */
  1226. #define    DB_SWAPBYTES        (-30891)/* Database needs byte swapping. */
  1227. #define    DB_TIMEOUT        (-30890)/* Timed out waiting for election. */
  1228. #define    DB_TXN_CKP        (-30889)/* Encountered ckp record in log. */
  1229. #define    DB_VERIFY_FATAL        (-30888)/* DB->verify cannot proceed. */
  1230.  
  1231. /* Database handle. */
  1232. struct __db {
  1233.     /*******************************************************
  1234.      * Public: owned by the application.
  1235.      *******************************************************/
  1236.     u_int32_t pgsize;        /* Database logical page size. */
  1237.  
  1238.                     /* Callbacks. */
  1239.     int (*db_append_recno) __P((DB *, DBT *, db_recno_t));
  1240.     void (*db_feedback) __P((DB *, int, int));
  1241.     int (*dup_compare) __P((DB *, const DBT *, const DBT *));
  1242.  
  1243.     void    *app_private;        /* Application-private handle. */
  1244.  
  1245.     /*******************************************************
  1246.      * Private: owned by DB.
  1247.      *******************************************************/
  1248.     DB_ENV    *dbenv;            /* Backing environment. */
  1249.  
  1250.     DBTYPE     type;            /* DB access method type. */
  1251.  
  1252.     DB_MPOOLFILE *mpf;        /* Backing buffer pool. */
  1253.  
  1254.     DB_MUTEX *mutexp;        /* Synchronization for free threading */
  1255.  
  1256.     char *fname, *dname;        /* File/database passed to DB->open. */
  1257.     u_int32_t open_flags;        /* Flags passed to DB->open. */
  1258.  
  1259.     u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
  1260.  
  1261.     u_int32_t adj_fileid;        /* File's unique ID for curs. adj. */
  1262.  
  1263. #define    DB_LOGFILEID_INVALID    -1
  1264.     FNAME *log_filename;        /* File's naming info for logging. */
  1265.  
  1266.     db_pgno_t meta_pgno;        /* Meta page number */
  1267.     u_int32_t lid;            /* Locker id for handle locking. */
  1268.     u_int32_t cur_lid;        /* Current handle lock holder. */
  1269.     u_int32_t associate_lid;    /* Locker id for DB->associate call. */
  1270.     DB_LOCK    handle_lock;        /* Lock held on this handle. */
  1271.  
  1272.     u_int     cl_id;            /* RPC: remote client id. */
  1273.  
  1274.     time_t     timestamp;        /* Handle timestamp for replication. */
  1275.  
  1276.     /*
  1277.      * Returned data memory for DB->get() and friends.
  1278.      */
  1279.     DBT     my_rskey;        /* Secondary key. */
  1280.     DBT     my_rkey;        /* [Primary] key. */
  1281.     DBT     my_rdata;        /* Data. */
  1282.  
  1283.     /*
  1284.      * !!!
  1285.      * Some applications use DB but implement their own locking outside of
  1286.      * DB.  If they're using fcntl(2) locking on the underlying database
  1287.      * file, and we open and close a file descriptor for that file, we will
  1288.      * discard their locks.  The DB_FCNTL_LOCKING flag to DB->open is an
  1289.      * undocumented interface to support this usage which leaves any file
  1290.      * descriptors we open until DB->close.  This will only work with the
  1291.      * DB->open interface and simple caches, e.g., creating a transaction
  1292.      * thread may open/close file descriptors this flag doesn't protect.
  1293.      * Locking with fcntl(2) on a file that you don't own is a very, very
  1294.      * unsafe thing to do.  'Nuff said.
  1295.      */
  1296.     DB_FH    *saved_open_fhp;    /* Saved file handle. */
  1297.  
  1298.     /*
  1299.      * Linked list of DBP's, linked from the DB_ENV, used to keep track
  1300.      * of all open db handles for cursor adjustment.
  1301.      *
  1302.      * !!!
  1303.      * Explicit representations of structures from queue.h.
  1304.      * LIST_ENTRY(__db) dblistlinks;
  1305.      */
  1306.     struct {
  1307.         struct __db *le_next;
  1308.         struct __db **le_prev;
  1309.     } dblistlinks;
  1310.  
  1311.     /*
  1312.      * Cursor queues.
  1313.      *
  1314.      * !!!
  1315.      * Explicit representations of structures from queue.h.
  1316.      * TAILQ_HEAD(__cq_fq, __dbc) free_queue;
  1317.      * TAILQ_HEAD(__cq_aq, __dbc) active_queue;
  1318.      * TAILQ_HEAD(__cq_jq, __dbc) join_queue;
  1319.      */
  1320.     struct __cq_fq {
  1321.         struct __dbc *tqh_first;
  1322.         struct __dbc **tqh_last;
  1323.     } free_queue;
  1324.     struct __cq_aq {
  1325.         struct __dbc *tqh_first;
  1326.         struct __dbc **tqh_last;
  1327.     } active_queue;
  1328.     struct __cq_jq {
  1329.         struct __dbc *tqh_first;
  1330.         struct __dbc **tqh_last;
  1331.     } join_queue;
  1332.  
  1333.     /*
  1334.      * Secondary index support.
  1335.      *
  1336.      * Linked list of secondary indices -- set in the primary.
  1337.      *
  1338.      * !!!
  1339.      * Explicit representations of structures from queue.h.
  1340.      * LIST_HEAD(s_secondaries, __db);
  1341.      */
  1342.     struct {
  1343.         struct __db *lh_first;
  1344.     } s_secondaries;
  1345.  
  1346.     /*
  1347.      * List entries for secondaries, and reference count of how
  1348.      * many threads are updating this secondary (see __db_c_put).
  1349.      *
  1350.      * !!!
  1351.      * Note that these are synchronized by the primary's mutex, but
  1352.      * filled in in the secondaries.
  1353.      *
  1354.      * !!!
  1355.      * Explicit representations of structures from queue.h.
  1356.      * LIST_ENTRY(__db) s_links;
  1357.      */
  1358.     struct {
  1359.         struct __db *le_next;
  1360.         struct __db **le_prev;
  1361.     } s_links;
  1362.     u_int32_t s_refcnt;
  1363.  
  1364.     /* Secondary callback and free functions -- set in the secondary. */
  1365.     int    (*s_callback) __P((DB *, const DBT *, const DBT *, DBT *));
  1366.  
  1367.     /* Reference to primary -- set in the secondary. */
  1368.     DB    *s_primary;
  1369.  
  1370.     /* API-private structure: used by DB 1.85, C++, Java, Perl and Tcl */
  1371.     void    *api_internal;
  1372.  
  1373.     /* Subsystem-private structure. */
  1374.     void    *bt_internal;        /* Btree/Recno access method. */
  1375.     void    *h_internal;        /* Hash access method. */
  1376.     void    *q_internal;        /* Queue access method. */
  1377.     void    *xa_internal;        /* XA. */
  1378.  
  1379.                     /* Methods. */
  1380.     int  (*associate) __P((DB *, DB_TXN *, DB *, int (*)(DB *, const DBT *,
  1381.         const DBT *, DBT *), u_int32_t));
  1382.     int  (*close) __P((DB *, u_int32_t));
  1383.     int  (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
  1384.     int  (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
  1385.     int  (*dump) __P((DB *,
  1386.         const char *, int (*)(void *, const void *), void *, int, int));
  1387.     void (*err) __P((DB *, int, const char *, ...));
  1388.     void (*errx) __P((DB *, const char *, ...));
  1389.     int  (*fd) __P((DB *, int *));
  1390.     int  (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
  1391.     int  (*pget) __P((DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t));
  1392.     int  (*get_byteswapped) __P((DB *, int *));
  1393.     int  (*get_cachesize) __P((DB *, u_int32_t *, u_int32_t *, int *));
  1394.     int  (*get_dbname) __P((DB *, const char **, const char **));
  1395.     int  (*get_encrypt_flags) __P((DB *, u_int32_t *));
  1396.     DB_ENV *(*get_env) __P((DB *));
  1397.     void (*get_errfile) __P((DB *, FILE **));
  1398.     void (*get_errpfx) __P((DB *, const char **));
  1399.     int  (*get_flags) __P((DB *, u_int32_t *));
  1400.     int  (*get_lorder) __P((DB *, int *));
  1401.     int  (*get_open_flags) __P((DB *, u_int32_t *));
  1402.     int  (*get_pagesize) __P((DB *, u_int32_t *));
  1403.     int  (*get_transactional) __P((DB *));
  1404.     int  (*get_type) __P((DB *, DBTYPE *));
  1405.     int  (*join) __P((DB *, DBC **, DBC **, u_int32_t));
  1406.     int  (*key_range) __P((DB *,
  1407.         DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t));
  1408.     int  (*open) __P((DB *, DB_TXN *,
  1409.         const char *, const char *, DBTYPE, u_int32_t, int));
  1410.     int  (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
  1411.     int  (*remove) __P((DB *, const char *, const char *, u_int32_t));
  1412.     int  (*rename) __P((DB *,
  1413.         const char *, const char *, const char *, u_int32_t));
  1414.     int  (*truncate) __P((DB *, DB_TXN *, u_int32_t *, u_int32_t));
  1415.     int  (*set_append_recno) __P((DB *, int (*)(DB *, DBT *, db_recno_t)));
  1416.     int  (*set_alloc) __P((DB *, void *(*)(size_t),
  1417.         void *(*)(void *, size_t), void (*)(void *)));
  1418.     int  (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int));
  1419.     int  (*set_dup_compare) __P((DB *,
  1420.         int (*)(DB *, const DBT *, const DBT *)));
  1421.     int  (*set_encrypt) __P((DB *, const char *, u_int32_t));
  1422.     void (*set_errcall) __P((DB *,
  1423.         void (*)(const DB_ENV *, const char *, const char *)));
  1424.     void (*set_errfile) __P((DB *, FILE *));
  1425.     void (*set_errpfx) __P((DB *, const char *));
  1426.     int  (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
  1427.     int  (*set_flags) __P((DB *, u_int32_t));
  1428.     int  (*set_lorder) __P((DB *, int));
  1429.     void (*set_msgcall) __P((DB *, void (*)(const DB_ENV *, const char *)));
  1430.     void (*get_msgfile) __P((DB *, FILE **));
  1431.     void (*set_msgfile) __P((DB *, FILE *));
  1432.     int  (*set_pagesize) __P((DB *, u_int32_t));
  1433.     int  (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
  1434.     int  (*stat) __P((DB *, DB_TXN *, void *, u_int32_t));
  1435.     int  (*stat_print) __P((DB *, u_int32_t));
  1436.     int  (*sync) __P((DB *, u_int32_t));
  1437.     int  (*upgrade) __P((DB *, const char *, u_int32_t));
  1438.     int  (*verify) __P((DB *,
  1439.         const char *, const char *, FILE *, u_int32_t));
  1440.  
  1441.     int  (*get_bt_minkey) __P((DB *, u_int32_t *));
  1442.     int  (*set_bt_compare) __P((DB *,
  1443.         int (*)(DB *, const DBT *, const DBT *)));
  1444.     int  (*set_bt_maxkey) __P((DB *, u_int32_t));
  1445.     int  (*set_bt_minkey) __P((DB *, u_int32_t));
  1446.     int  (*set_bt_prefix) __P((DB *,
  1447.         size_t (*)(DB *, const DBT *, const DBT *)));
  1448.  
  1449.     int  (*get_h_ffactor) __P((DB *, u_int32_t *));
  1450.     int  (*get_h_nelem) __P((DB *, u_int32_t *));
  1451.     int  (*set_h_ffactor) __P((DB *, u_int32_t));
  1452.     int  (*set_h_hash) __P((DB *,
  1453.         u_int32_t (*)(DB *, const void *, u_int32_t)));
  1454.     int  (*set_h_nelem) __P((DB *, u_int32_t));
  1455.  
  1456.     int  (*get_re_delim) __P((DB *, int *));
  1457.     int  (*get_re_len) __P((DB *, u_int32_t *));
  1458.     int  (*get_re_pad) __P((DB *, int *));
  1459.     int  (*get_re_source) __P((DB *, const char **));
  1460.     int  (*set_re_delim) __P((DB *, int));
  1461.     int  (*set_re_len) __P((DB *, u_int32_t));
  1462.     int  (*set_re_pad) __P((DB *, int));
  1463.     int  (*set_re_source) __P((DB *, const char *));
  1464.  
  1465.     int  (*get_q_extentsize) __P((DB *, u_int32_t *));
  1466.     int  (*set_q_extentsize) __P((DB *, u_int32_t));
  1467.  
  1468.     int  (*db_am_remove) __P((DB *, DB_TXN *, const char *, const char *));
  1469.     int  (*db_am_rename) __P((DB *, DB_TXN *,
  1470.         const char *, const char *, const char *));
  1471.  
  1472.     /*
  1473.      * Never called; these are a place to save function pointers
  1474.      * so that we can undo an associate.
  1475.      */
  1476.     int  (*stored_get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
  1477.     int  (*stored_close) __P((DB *, u_int32_t));
  1478.  
  1479. #define    DB_OK_BTREE    0x01
  1480. #define    DB_OK_HASH    0x02
  1481. #define    DB_OK_QUEUE    0x04
  1482. #define    DB_OK_RECNO    0x08
  1483.     u_int32_t    am_ok;        /* Legal AM choices. */
  1484.  
  1485. #define    DB_AM_CHKSUM        0x00000001 /* Checksumming. */
  1486. #define    DB_AM_CL_WRITER        0x00000002 /* Allow writes in client replica. */
  1487. #define    DB_AM_COMPENSATE    0x00000004 /* Created by compensating txn. */
  1488. #define    DB_AM_CREATED        0x00000008 /* Database was created upon open. */
  1489. #define    DB_AM_CREATED_MSTR    0x00000010 /* Encompassing file was created. */
  1490. #define    DB_AM_DBM_ERROR        0x00000020 /* Error in DBM/NDBM database. */
  1491. #define    DB_AM_DELIMITER        0x00000040 /* Variable length delimiter set. */
  1492. #define    DB_AM_DIRTY        0x00000080 /* Support Dirty Reads. */
  1493. #define    DB_AM_DISCARD        0x00000100 /* Discard any cached pages. */
  1494. #define    DB_AM_DUP        0x00000200 /* DB_DUP. */
  1495. #define    DB_AM_DUPSORT        0x00000400 /* DB_DUPSORT. */
  1496. #define    DB_AM_ENCRYPT        0x00000800 /* Encryption. */
  1497. #define    DB_AM_FIXEDLEN        0x00001000 /* Fixed-length records. */
  1498. #define    DB_AM_INMEM        0x00002000 /* In-memory; no sync on close. */
  1499. #define    DB_AM_INORDER        0x00004000 /* DB_INORDER. */
  1500. #define    DB_AM_IN_RENAME        0x00008000 /* File is being renamed. */
  1501. #define    DB_AM_NOT_DURABLE    0x00010000 /* Do not log changes. */
  1502. #define    DB_AM_OPEN_CALLED    0x00020000 /* DB->open called. */
  1503. #define    DB_AM_PAD        0x00040000 /* Fixed-length record pad. */
  1504. #define    DB_AM_PGDEF        0x00080000 /* Page size was defaulted. */
  1505. #define    DB_AM_RDONLY        0x00100000 /* Database is readonly. */
  1506. #define    DB_AM_RECNUM        0x00200000 /* DB_RECNUM. */
  1507. #define    DB_AM_RECOVER        0x00400000 /* DB opened by recovery routine. */
  1508. #define    DB_AM_RENUMBER        0x00800000 /* DB_RENUMBER. */
  1509. #define    DB_AM_REPLICATION    0x01000000 /* An internal replication file. */
  1510. #define    DB_AM_REVSPLITOFF    0x02000000 /* DB_REVSPLITOFF. */
  1511. #define    DB_AM_SECONDARY        0x04000000 /* Database is a secondary index. */
  1512. #define    DB_AM_SNAPSHOT        0x08000000 /* DB_SNAPSHOT. */
  1513. #define    DB_AM_SUBDB        0x10000000 /* Subdatabases supported. */
  1514. #define    DB_AM_SWAP        0x20000000 /* Pages need to be byte-swapped. */
  1515. #define    DB_AM_TXN        0x40000000 /* Opened in a transaction. */
  1516. #define    DB_AM_VERIFYING        0x80000000 /* DB handle is in the verifier. */
  1517.     u_int32_t orig_flags;           /* Flags at  open, for refresh. */
  1518.     u_int32_t flags;
  1519. };
  1520.  
  1521. /*
  1522.  * Macros for bulk get.  These are only intended for the C API.
  1523.  * For C++, use DbMultiple*Iterator.
  1524.  */
  1525. #define    DB_MULTIPLE_INIT(pointer, dbt)                    \
  1526.     (pointer = (u_int8_t *)(dbt)->data +                \
  1527.         (dbt)->ulen - sizeof(u_int32_t))
  1528. #define    DB_MULTIPLE_NEXT(pointer, dbt, retdata, retdlen)        \
  1529.     do {                                \
  1530.         if (*((u_int32_t *)(pointer)) == (u_int32_t)-1) {    \
  1531.             retdata = NULL;                    \
  1532.             pointer = NULL;                    \
  1533.             break;                        \
  1534.         }                            \
  1535.         retdata = (u_int8_t *)                    \
  1536.             (dbt)->data + *(u_int32_t *)(pointer);        \
  1537.         (pointer) = (u_int32_t *)(pointer) - 1;            \
  1538.         retdlen = *(u_int32_t *)(pointer);            \
  1539.         (pointer) = (u_int32_t *)(pointer) - 1;            \
  1540.         if (retdlen == 0 &&                    \
  1541.             retdata == (u_int8_t *)(dbt)->data)            \
  1542.             retdata = NULL;                    \
  1543.     } while (0)
  1544. #define    DB_MULTIPLE_KEY_NEXT(pointer, dbt, retkey, retklen, retdata, retdlen) \
  1545.     do {                                \
  1546.         if (*((u_int32_t *)(pointer)) == (u_int32_t)-1) {    \
  1547.             retdata = NULL;                    \
  1548.             retkey = NULL;                    \
  1549.             pointer = NULL;                    \
  1550.             break;                        \
  1551.         }                            \
  1552.         retkey = (u_int8_t *)                    \
  1553.             (dbt)->data + *(u_int32_t *)(pointer);        \
  1554.         (pointer) = (u_int32_t *)(pointer) - 1;            \
  1555.         retklen = *(u_int32_t *)(pointer);            \
  1556.         (pointer) = (u_int32_t *)(pointer) - 1;            \
  1557.         retdata = (u_int8_t *)                    \
  1558.             (dbt)->data + *(u_int32_t *)(pointer);        \
  1559.         (pointer) = (u_int32_t *)(pointer) - 1;            \
  1560.         retdlen = *(u_int32_t *)(pointer);            \
  1561.         (pointer) = (u_int32_t *)(pointer) - 1;            \
  1562.     } while (0)
  1563.  
  1564. #define    DB_MULTIPLE_RECNO_NEXT(pointer, dbt, recno, retdata, retdlen)   \
  1565.     do {                                \
  1566.         if (*((u_int32_t *)(pointer)) == (u_int32_t)0) {    \
  1567.             recno = 0;                    \
  1568.             retdata = NULL;                    \
  1569.             pointer = NULL;                    \
  1570.             break;                        \
  1571.         }                            \
  1572.         recno = *(u_int32_t *)(pointer);            \
  1573.         (pointer) = (u_int32_t *)(pointer) - 1;            \
  1574.         retdata = (u_int8_t *)                    \
  1575.             (dbt)->data + *(u_int32_t *)(pointer);        \
  1576.         (pointer) = (u_int32_t *)(pointer) - 1;            \
  1577.         retdlen = *(u_int32_t *)(pointer);            \
  1578.         (pointer) = (u_int32_t *)(pointer) - 1;            \
  1579.     } while (0)
  1580.  
  1581. /*******************************************************
  1582.  * Access method cursors.
  1583.  *******************************************************/
  1584. struct __dbc {
  1585.     DB *dbp;            /* Related DB access method. */
  1586.     DB_TXN     *txn;            /* Associated transaction. */
  1587.  
  1588.     /*
  1589.      * Active/free cursor queues.
  1590.      *
  1591.      * !!!
  1592.      * Explicit representations of structures from queue.h.
  1593.      * TAILQ_ENTRY(__dbc) links;
  1594.      */
  1595.     struct {
  1596.         DBC *tqe_next;
  1597.         DBC **tqe_prev;
  1598.     } links;
  1599.  
  1600.     /*
  1601.      * The DBT *'s below are used by the cursor routines to return
  1602.      * data to the user when DBT flags indicate that DB should manage
  1603.      * the returned memory.  They point at a DBT containing the buffer
  1604.      * and length that will be used, and "belonging" to the handle that
  1605.      * should "own" this memory.  This may be a "my_*" field of this
  1606.      * cursor--the default--or it may be the corresponding field of
  1607.      * another cursor, a DB handle, a join cursor, etc.  In general, it
  1608.      * will be whatever handle the user originally used for the current
  1609.      * DB interface call.
  1610.      */
  1611.     DBT     *rskey;        /* Returned secondary key. */
  1612.     DBT     *rkey;            /* Returned [primary] key. */
  1613.     DBT     *rdata;        /* Returned data. */
  1614.  
  1615.     DBT      my_rskey;        /* Space for returned secondary key. */
  1616.     DBT      my_rkey;        /* Space for returned [primary] key. */
  1617.     DBT      my_rdata;        /* Space for returned data. */
  1618.  
  1619.     u_int32_t lid;            /* Default process' locker id. */
  1620.     u_int32_t locker;        /* Locker for this operation. */
  1621.     DBT      lock_dbt;        /* DBT referencing lock. */
  1622.     DB_LOCK_ILOCK lock;        /* Object to be locked. */
  1623.     DB_LOCK      mylock;        /* CDB lock held on this cursor. */
  1624.  
  1625.     u_int      cl_id;        /* Remote client id. */
  1626.  
  1627.     DBTYPE      dbtype;        /* Cursor type. */
  1628.  
  1629.     DBC_INTERNAL *internal;        /* Access method private. */
  1630.  
  1631.     int (*c_close) __P((DBC *));    /* Methods: public. */
  1632.     int (*c_count) __P((DBC *, db_recno_t *, u_int32_t));
  1633.     int (*c_del) __P((DBC *, u_int32_t));
  1634.     int (*c_dup) __P((DBC *, DBC **, u_int32_t));
  1635.     int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
  1636.     int (*c_pget) __P((DBC *, DBT *, DBT *, DBT *, u_int32_t));
  1637.     int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
  1638.  
  1639.                     /* Methods: private. */
  1640.     int (*c_am_bulk) __P((DBC *, DBT *, u_int32_t));
  1641.     int (*c_am_close) __P((DBC *, db_pgno_t, int *));
  1642.     int (*c_am_del) __P((DBC *));
  1643.     int (*c_am_destroy) __P((DBC *));
  1644.     int (*c_am_get) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
  1645.     int (*c_am_put) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
  1646.     int (*c_am_writelock) __P((DBC *));
  1647.  
  1648. #define    DBC_ACTIVE     0x0001        /* Cursor in use. */
  1649. #define    DBC_COMPENSATE     0x0002        /* Cursor compensating, don't lock. */
  1650. #define    DBC_DEGREE_2     0x0004        /* Cursor has degree 2 isolation. */
  1651. #define    DBC_DIRTY_READ     0x0008        /* Cursor supports dirty reads. */
  1652. #define    DBC_OPD         0x0010        /* Cursor references off-page dups. */
  1653. #define    DBC_RECOVER     0x0020        /* Recovery cursor; don't log/lock. */
  1654. #define    DBC_RMW         0x0040        /* Acquire write flag in read op. */
  1655. #define    DBC_TRANSIENT     0x0080        /* Cursor is transient. */
  1656. #define    DBC_WRITECURSOR     0x0100        /* Cursor may be used to write (CDB). */
  1657. #define    DBC_WRITER     0x0200        /* Cursor immediately writing (CDB). */
  1658. #define    DBC_MULTIPLE     0x0400        /* Return Multiple data. */
  1659. #define    DBC_MULTIPLE_KEY 0x0800        /* Return Multiple keys and data. */
  1660. #define    DBC_OWN_LID     0x1000        /* Free lock id on destroy. */
  1661.     u_int32_t flags;
  1662. };
  1663.  
  1664. /* Key range statistics structure */
  1665. struct __key_range {
  1666.     double less;
  1667.     double equal;
  1668.     double greater;
  1669. };
  1670.  
  1671. /* Btree/Recno statistics structure. */
  1672. struct __db_bt_stat {
  1673.     u_int32_t bt_magic;        /* Magic number. */
  1674.     u_int32_t bt_version;        /* Version number. */
  1675.     u_int32_t bt_metaflags;        /* Metadata flags. */
  1676.     u_int32_t bt_nkeys;        /* Number of unique keys. */
  1677.     u_int32_t bt_ndata;        /* Number of data items. */
  1678.     u_int32_t bt_pagesize;        /* Page size. */
  1679.     u_int32_t bt_maxkey;        /* Maxkey value. */
  1680.     u_int32_t bt_minkey;        /* Minkey value. */
  1681.     u_int32_t bt_re_len;        /* Fixed-length record length. */
  1682.     u_int32_t bt_re_pad;        /* Fixed-length record pad. */
  1683.     u_int32_t bt_levels;        /* Tree levels. */
  1684.     u_int32_t bt_int_pg;        /* Internal pages. */
  1685.     u_int32_t bt_leaf_pg;        /* Leaf pages. */
  1686.     u_int32_t bt_dup_pg;        /* Duplicate pages. */
  1687.     u_int32_t bt_over_pg;        /* Overflow pages. */
  1688.     u_int32_t bt_empty_pg;        /* Empty pages. */
  1689.     u_int32_t bt_free;        /* Pages on the free list. */
  1690.     u_int32_t bt_int_pgfree;    /* Bytes free in internal pages. */
  1691.     u_int32_t bt_leaf_pgfree;    /* Bytes free in leaf pages. */
  1692.     u_int32_t bt_dup_pgfree;    /* Bytes free in duplicate pages. */
  1693.     u_int32_t bt_over_pgfree;    /* Bytes free in overflow pages. */
  1694. };
  1695.  
  1696. /* Hash statistics structure. */
  1697. struct __db_h_stat {
  1698.     u_int32_t hash_magic;        /* Magic number. */
  1699.     u_int32_t hash_version;        /* Version number. */
  1700.     u_int32_t hash_metaflags;    /* Metadata flags. */
  1701.     u_int32_t hash_nkeys;        /* Number of unique keys. */
  1702.     u_int32_t hash_ndata;        /* Number of data items. */
  1703.     u_int32_t hash_pagesize;    /* Page size. */
  1704.     u_int32_t hash_ffactor;        /* Fill factor specified at create. */
  1705.     u_int32_t hash_buckets;        /* Number of hash buckets. */
  1706.     u_int32_t hash_free;        /* Pages on the free list. */
  1707.     u_int32_t hash_bfree;        /* Bytes free on bucket pages. */
  1708.     u_int32_t hash_bigpages;    /* Number of big key/data pages. */
  1709.     u_int32_t hash_big_bfree;    /* Bytes free on big item pages. */
  1710.     u_int32_t hash_overflows;    /* Number of overflow pages. */
  1711.     u_int32_t hash_ovfl_free;    /* Bytes free on ovfl pages. */
  1712.     u_int32_t hash_dup;        /* Number of dup pages. */
  1713.     u_int32_t hash_dup_free;    /* Bytes free on duplicate pages. */
  1714. };
  1715.  
  1716. /* Queue statistics structure. */
  1717. struct __db_qam_stat {
  1718.     u_int32_t qs_magic;        /* Magic number. */
  1719.     u_int32_t qs_version;        /* Version number. */
  1720.     u_int32_t qs_metaflags;        /* Metadata flags. */
  1721.     u_int32_t qs_nkeys;        /* Number of unique keys. */
  1722.     u_int32_t qs_ndata;        /* Number of data items. */
  1723.     u_int32_t qs_pagesize;        /* Page size. */
  1724.     u_int32_t qs_extentsize;    /* Pages per extent. */
  1725.     u_int32_t qs_pages;        /* Data pages. */
  1726.     u_int32_t qs_re_len;        /* Fixed-length record length. */
  1727.     u_int32_t qs_re_pad;        /* Fixed-length record pad. */
  1728.     u_int32_t qs_pgfree;        /* Bytes free in data pages. */
  1729.     u_int32_t qs_first_recno;    /* First not deleted record. */
  1730.     u_int32_t qs_cur_recno;        /* Next available record number. */
  1731. };
  1732.  
  1733. /*******************************************************
  1734.  * Environment.
  1735.  *******************************************************/
  1736. #define    DB_REGION_MAGIC    0x120897    /* Environment magic number. */
  1737.  
  1738. /* Database Environment handle. */
  1739. struct __db_env {
  1740.     /*******************************************************
  1741.      * Public: owned by the application.
  1742.      *******************************************************/
  1743.                     /* Error message callback. */
  1744.     void (*db_errcall) __P((const DB_ENV *, const char *, const char *));
  1745.     FILE        *db_errfile;    /* Error message file stream. */
  1746.     const char    *db_errpfx;    /* Error message prefix. */
  1747.  
  1748.     FILE        *db_msgfile;    /* Statistics message file stream. */
  1749.                     /* Statistics message callback. */
  1750.     void (*db_msgcall) __P((const DB_ENV *, const char *));
  1751.  
  1752.                     /* Other Callbacks. */
  1753.     void (*db_feedback) __P((DB_ENV *, int, int));
  1754.     void (*db_paniccall) __P((DB_ENV *, int));
  1755.  
  1756.                     /* App-specified alloc functions. */
  1757.     void *(*db_malloc) __P((size_t));
  1758.     void *(*db_realloc) __P((void *, size_t));
  1759.     void (*db_free) __P((void *));
  1760.  
  1761.     /*
  1762.      * Currently, the verbose list is a bit field with room for 32
  1763.      * entries.  There's no reason that it needs to be limited, if
  1764.      * there are ever more than 32 entries, convert to a bit array.
  1765.      */
  1766. #define    DB_VERB_DEADLOCK    0x0001    /* Deadlock detection information. */
  1767. #define    DB_VERB_RECOVERY    0x0002    /* Recovery information. */
  1768. #define    DB_VERB_REPLICATION    0x0004    /* Replication information. */
  1769. #define    DB_VERB_WAITSFOR    0x0008    /* Dump waits-for table. */
  1770.     u_int32_t     verbose;    /* Verbose output. */
  1771.  
  1772.     void        *app_private;    /* Application-private handle. */
  1773.  
  1774.     int (*app_dispatch)        /* User-specified recovery dispatch. */
  1775.         __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
  1776.  
  1777.     /* Locking. */
  1778.     u_int8_t    *lk_conflicts;    /* Two dimensional conflict matrix. */
  1779.     int         lk_modes;    /* Number of lock modes in table. */
  1780.     u_int32_t     lk_max;    /* Maximum number of locks. */
  1781.     u_int32_t     lk_max_lockers;/* Maximum number of lockers. */
  1782.     u_int32_t     lk_max_objects;/* Maximum number of locked objects. */
  1783.     u_int32_t     lk_detect;    /* Deadlock detect on all conflicts. */
  1784.     db_timeout_t     lk_timeout;    /* Lock timeout period. */
  1785.  
  1786.     /* Logging. */
  1787.     u_int32_t     lg_bsize;    /* Buffer size. */
  1788.     u_int32_t     lg_size;    /* Log file size. */
  1789.     u_int32_t     lg_regionmax;    /* Region size. */
  1790.  
  1791.     /* Memory pool. */
  1792.     u_int32_t     mp_gbytes;    /* Cachesize: GB. */
  1793.     u_int32_t     mp_bytes;    /* Cachesize: Bytes. */
  1794.     u_int         mp_ncache;    /* Number of cache regions. */
  1795.     size_t         mp_mmapsize;    /* Maximum file size for mmap. */
  1796.     int         mp_maxopenfd;    /* Maximum open file descriptors. */
  1797.     int         mp_maxwrite;    /* Maximum buffers to write. */
  1798.     int                /* Sleep after writing max buffers. */
  1799.              mp_maxwrite_sleep;
  1800.  
  1801.     /* Replication */
  1802.     int         rep_eid;    /* environment id. */
  1803.     int        (*rep_send)    /* Send function. */
  1804.                 __P((DB_ENV *, const DBT *, const DBT *,
  1805.                 const DB_LSN *, int, u_int32_t));
  1806.  
  1807.     /* Transactions. */
  1808.     u_int32_t     tx_max;    /* Maximum number of transactions. */
  1809.     time_t         tx_timestamp;    /* Recover to specific timestamp. */
  1810.     db_timeout_t     tx_timeout;    /* Timeout for transactions. */
  1811.  
  1812.     /*******************************************************
  1813.      * Private: owned by DB.
  1814.      *******************************************************/
  1815.                     /* User files, paths. */
  1816.     char        *db_home;    /* Database home. */
  1817.     char        *db_log_dir;    /* Database log file directory. */
  1818.     char        *db_tmp_dir;    /* Database tmp file directory. */
  1819.  
  1820.     char           **db_data_dir;    /* Database data file directories. */
  1821.     int         data_cnt;    /* Database data file slots. */
  1822.     int         data_next;    /* Next Database data file slot. */
  1823.  
  1824.     int         db_mode;    /* Default open permissions. */
  1825.     int         dir_mode;    /* Intermediate directory perms. */
  1826.     u_int32_t     env_lid;    /* Locker ID in non-threaded handles. */
  1827.     u_int32_t     open_flags;    /* Flags passed to DB_ENV->open. */
  1828.  
  1829.     void        *reginfo;    /* REGINFO structure reference. */
  1830.     DB_FH        *lockfhp;    /* fcntl(2) locking file handle. */
  1831.  
  1832.     int          (**recover_dtab)    /* Dispatch table for recover funcs. */
  1833.                 __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
  1834.     size_t         recover_dtab_size;
  1835.                     /* Slots in the dispatch table. */
  1836.  
  1837.     void        *cl_handle;    /* RPC: remote client handle. */
  1838.     u_int         cl_id;        /* RPC: remote client env id. */
  1839.  
  1840.     int         db_ref;    /* DB reference count. */
  1841.  
  1842.     long         shm_key;    /* shmget(2) key. */
  1843.     u_int32_t     tas_spins;    /* test-and-set spins. */
  1844.  
  1845.     /*
  1846.      * List of open DB handles for this DB_ENV, used for cursor
  1847.      * adjustment.  Must be protected for multi-threaded support.
  1848.      *
  1849.      * !!!
  1850.      * As this structure is allocated in per-process memory, the
  1851.      * mutex may need to be stored elsewhere on architectures unable
  1852.      * to support mutexes in heap memory, e.g. HP/UX 9.
  1853.      *
  1854.      * !!!
  1855.      * Explicit representation of structure in queue.h.
  1856.      * LIST_HEAD(dblist, __db);
  1857.      */
  1858.     DB_MUTEX    *dblist_mutexp;    /* Mutex. */
  1859.     struct {
  1860.         struct __db *lh_first;
  1861.     } dblist;
  1862.  
  1863.     /*
  1864.      * XA support.
  1865.      *
  1866.      * !!!
  1867.      * Explicit representations of structures from queue.h.
  1868.      * TAILQ_ENTRY(__db_env) links;
  1869.      * TAILQ_HEAD(xa_txn, __db_txn);
  1870.      */
  1871.     struct {
  1872.         struct __db_env *tqe_next;
  1873.         struct __db_env **tqe_prev;
  1874.     } links;
  1875.     struct __xa_txn {    /* XA Active Transactions. */
  1876.         struct __db_txn *tqh_first;
  1877.         struct __db_txn **tqh_last;
  1878.     } xa_txn;
  1879.     int         xa_rmid;    /* XA Resource Manager ID. */
  1880.  
  1881.     /* API-private structure. */
  1882.     void        *api1_internal;    /* C++, Perl API private */
  1883.     void        *api2_internal;    /* Java API private */
  1884.  
  1885.     char        *passwd;    /* Cryptography support. */
  1886.     size_t         passwd_len;
  1887.     void        *crypto_handle;    /* Primary handle. */
  1888.     DB_MUTEX    *mt_mutexp;    /* Mersenne Twister mutex. */
  1889.     int         mti;        /* Mersenne Twister index. */
  1890.     u_long        *mt;        /* Mersenne Twister state vector. */
  1891.  
  1892.                     /* DB_ENV Methods. */
  1893.     int  (*close) __P((DB_ENV *, u_int32_t));
  1894.     int  (*dbremove) __P((DB_ENV *,
  1895.         DB_TXN *, const char *, const char *, u_int32_t));
  1896.     int  (*dbrename) __P((DB_ENV *, DB_TXN *,
  1897.         const char *, const char *, const char *, u_int32_t));
  1898.     void (*err) __P((const DB_ENV *, int, const char *, ...));
  1899.     void (*errx) __P((const DB_ENV *, const char *, ...));
  1900.     int  (*open) __P((DB_ENV *, const char *, u_int32_t, int));
  1901.     int  (*remove) __P((DB_ENV *, const char *, u_int32_t));
  1902.     int  (*stat_print) __P((DB_ENV *, u_int32_t));
  1903.  
  1904.                     /* House-keeping. */
  1905.     int  (*fileid_reset) __P((DB_ENV *, char *, int));
  1906.     int  (*is_bigendian) __P((void));
  1907.     int  (*lsn_reset) __P((DB_ENV *, char *, int));
  1908.     int  (*prdbt) __P((DBT *,
  1909.         int, const char *, void *, int (*)(void *, const void *), int));
  1910.  
  1911.                     /* Setters/getters. */
  1912.     int  (*set_alloc) __P((DB_ENV *, void *(*)(size_t),
  1913.         void *(*)(void *, size_t), void (*)(void *)));
  1914.     int  (*set_app_dispatch) __P((DB_ENV *,
  1915.         int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
  1916.     int  (*get_data_dirs) __P((DB_ENV *, const char ***));
  1917.     int  (*set_data_dir) __P((DB_ENV *, const char *));
  1918.     int  (*get_encrypt_flags) __P((DB_ENV *, u_int32_t *));
  1919.     int  (*set_encrypt) __P((DB_ENV *, const char *, u_int32_t));
  1920.     void (*set_errcall) __P((DB_ENV *,
  1921.         void (*)(const DB_ENV *, const char *, const char *)));
  1922.     void (*get_errfile) __P((DB_ENV *, FILE **));
  1923.     void (*set_errfile) __P((DB_ENV *, FILE *));
  1924.     void (*get_errpfx) __P((DB_ENV *, const char **));
  1925.     void (*set_errpfx) __P((DB_ENV *, const char *));
  1926.     int  (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
  1927.     int  (*get_flags) __P((DB_ENV *, u_int32_t *));
  1928.     int  (*set_flags) __P((DB_ENV *, u_int32_t, int));
  1929.     int  (*get_home) __P((DB_ENV *, const char **));
  1930.     int  (*set_intermediate_dir) __P((DB_ENV *, int, u_int32_t));
  1931.     int  (*get_open_flags) __P((DB_ENV *, u_int32_t *));
  1932.     int  (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
  1933.     int  (*set_rpc_server) __P((DB_ENV *,
  1934.         void *, const char *, long, long, u_int32_t));
  1935.     int  (*get_shm_key) __P((DB_ENV *, long *));
  1936.     int  (*set_shm_key) __P((DB_ENV *, long));
  1937.     void (*set_msgcall) __P((DB_ENV *,
  1938.         void (*)(const DB_ENV *, const char *)));
  1939.     void (*get_msgfile) __P((DB_ENV *, FILE **));
  1940.     void (*set_msgfile) __P((DB_ENV *, FILE *));
  1941.     int  (*get_tas_spins) __P((DB_ENV *, u_int32_t *));
  1942.     int  (*set_tas_spins) __P((DB_ENV *, u_int32_t));
  1943.     int  (*get_tmp_dir) __P((DB_ENV *, const char **));
  1944.     int  (*set_tmp_dir) __P((DB_ENV *, const char *));
  1945.     int  (*get_verbose) __P((DB_ENV *, u_int32_t, int *));
  1946.     int  (*set_verbose) __P((DB_ENV *, u_int32_t, int));
  1947.  
  1948.     void *lg_handle;        /* Log handle and methods. */
  1949.     int  (*get_lg_bsize) __P((DB_ENV *, u_int32_t *));
  1950.     int  (*set_lg_bsize) __P((DB_ENV *, u_int32_t));
  1951.     int  (*get_lg_dir) __P((DB_ENV *, const char **));
  1952.     int  (*set_lg_dir) __P((DB_ENV *, const char *));
  1953.     int  (*get_lg_max) __P((DB_ENV *, u_int32_t *));
  1954.     int  (*set_lg_max) __P((DB_ENV *, u_int32_t));
  1955.     int  (*get_lg_regionmax) __P((DB_ENV *, u_int32_t *));
  1956.     int  (*set_lg_regionmax) __P((DB_ENV *, u_int32_t));
  1957.     int  (*log_archive) __P((DB_ENV *, char **[], u_int32_t));
  1958.     int  (*log_cursor) __P((DB_ENV *, DB_LOGC **, u_int32_t));
  1959.     int  (*log_file) __P((DB_ENV *, const DB_LSN *, char *, size_t));
  1960.     int  (*log_flush) __P((DB_ENV *, const DB_LSN *));
  1961.     int  (*log_put) __P((DB_ENV *, DB_LSN *, const DBT *, u_int32_t));
  1962.     int  (*log_stat) __P((DB_ENV *, DB_LOG_STAT **, u_int32_t));
  1963.     int  (*log_stat_print) __P((DB_ENV *, u_int32_t));
  1964.  
  1965.     void *lk_handle;        /* Lock handle and methods. */
  1966.     int  (*get_lk_conflicts) __P((DB_ENV *, const u_int8_t **, int *));
  1967.     int  (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int));
  1968.     int  (*get_lk_detect) __P((DB_ENV *, u_int32_t *));
  1969.     int  (*set_lk_detect) __P((DB_ENV *, u_int32_t));
  1970.     int  (*set_lk_max) __P((DB_ENV *, u_int32_t));
  1971.     int  (*get_lk_max_locks) __P((DB_ENV *, u_int32_t *));
  1972.     int  (*set_lk_max_locks) __P((DB_ENV *, u_int32_t));
  1973.     int  (*get_lk_max_lockers) __P((DB_ENV *, u_int32_t *));
  1974.     int  (*set_lk_max_lockers) __P((DB_ENV *, u_int32_t));
  1975.     int  (*get_lk_max_objects) __P((DB_ENV *, u_int32_t *));
  1976.     int  (*set_lk_max_objects) __P((DB_ENV *, u_int32_t));
  1977.     int  (*lock_detect) __P((DB_ENV *, u_int32_t, u_int32_t, int *));
  1978.     int  (*lock_get) __P((DB_ENV *,
  1979.         u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
  1980.     int  (*lock_put) __P((DB_ENV *, DB_LOCK *));
  1981.     int  (*lock_id) __P((DB_ENV *, u_int32_t *));
  1982.     int  (*lock_id_free) __P((DB_ENV *, u_int32_t));
  1983.     int  (*lock_stat) __P((DB_ENV *, DB_LOCK_STAT **, u_int32_t));
  1984.     int  (*lock_stat_print) __P((DB_ENV *, u_int32_t));
  1985.     int  (*lock_vec) __P((DB_ENV *,
  1986.         u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
  1987.  
  1988.     void *mp_handle;        /* Mpool handle and methods. */
  1989.     int  (*get_cachesize) __P((DB_ENV *, u_int32_t *, u_int32_t *, int *));
  1990.     int  (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int));
  1991.     int  (*get_mp_mmapsize) __P((DB_ENV *, size_t *));
  1992.     int  (*set_mp_mmapsize) __P((DB_ENV *, size_t));
  1993.     int  (*get_mp_max_openfd) __P((DB_ENV *, int *));
  1994.     int  (*set_mp_max_openfd) __P((DB_ENV *, int));
  1995.     int  (*get_mp_max_write) __P((DB_ENV *, int *, int *));
  1996.     int  (*set_mp_max_write) __P((DB_ENV *, int, int));
  1997.     int  (*memp_fcreate) __P((DB_ENV *, DB_MPOOLFILE **, u_int32_t));
  1998.     int  (*memp_register) __P((DB_ENV *, int,
  1999.         int (*)(DB_ENV *, db_pgno_t, void *, DBT *),
  2000.         int (*)(DB_ENV *, db_pgno_t, void *, DBT *)));
  2001.     int  (*memp_stat) __P((DB_ENV *,
  2002.         DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, u_int32_t));
  2003.     int  (*memp_stat_print) __P((DB_ENV *, u_int32_t));
  2004.     int  (*memp_sync) __P((DB_ENV *, DB_LSN *));
  2005.     int  (*memp_trickle) __P((DB_ENV *, int, int *));
  2006.  
  2007.     void *rep_handle;        /* Replication handle and methods. */
  2008.     int  (*rep_elect) __P((DB_ENV *, int, int, int,
  2009.         u_int32_t, int *, u_int32_t));
  2010.     int  (*rep_flush) __P((DB_ENV *));
  2011.     int  (*rep_process_message) __P((DB_ENV *, DBT *, DBT *,
  2012.         int *, DB_LSN *));
  2013.     int  (*rep_start) __P((DB_ENV *, DBT *, u_int32_t));
  2014.     int  (*rep_stat) __P((DB_ENV *, DB_REP_STAT **, u_int32_t));
  2015.     int  (*rep_stat_print) __P((DB_ENV *, u_int32_t));
  2016.     int  (*get_rep_limit) __P((DB_ENV *, u_int32_t *, u_int32_t *));
  2017.     int  (*set_rep_limit) __P((DB_ENV *, u_int32_t, u_int32_t));
  2018.     int  (*set_rep_request) __P((DB_ENV *, u_int32_t, u_int32_t));
  2019.     int  (*set_rep_transport) __P((DB_ENV *, int,
  2020.         int (*) (DB_ENV *, const DBT *, const DBT *, const DB_LSN *,
  2021.         int, u_int32_t)));
  2022.  
  2023.     void *tx_handle;        /* Txn handle and methods. */
  2024.     int  (*get_tx_max) __P((DB_ENV *, u_int32_t *));
  2025.     int  (*set_tx_max) __P((DB_ENV *, u_int32_t));
  2026.     int  (*get_tx_timestamp) __P((DB_ENV *, time_t *));
  2027.     int  (*set_tx_timestamp) __P((DB_ENV *, time_t *));
  2028.     int  (*txn_begin) __P((DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t));
  2029.     int  (*txn_checkpoint) __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
  2030.     int  (*txn_recover) __P((DB_ENV *,
  2031.         DB_PREPLIST *, long, long *, u_int32_t));
  2032.     int  (*txn_stat) __P((DB_ENV *, DB_TXN_STAT **, u_int32_t));
  2033.     int  (*txn_stat_print) __P((DB_ENV *, u_int32_t));
  2034.     int  (*get_timeout) __P((DB_ENV *, db_timeout_t *, u_int32_t));
  2035.     int  (*set_timeout) __P((DB_ENV *, db_timeout_t, u_int32_t));
  2036.  
  2037. #define    DB_TEST_ELECTINIT     1    /* after __rep_elect_init */
  2038. #define    DB_TEST_ELECTVOTE1     2    /* after sending VOTE1 */
  2039. #define    DB_TEST_POSTDESTROY     3    /* after destroy op */
  2040. #define    DB_TEST_POSTLOG         4    /* after logging all pages */
  2041. #define    DB_TEST_POSTLOGMETA     5    /* after logging meta in btree */
  2042. #define    DB_TEST_POSTOPEN     6    /* after __os_open */
  2043. #define    DB_TEST_POSTSYNC     7    /* after syncing the log */
  2044. #define    DB_TEST_PREDESTROY     8    /* before destroy op */
  2045. #define    DB_TEST_PREOPEN         9    /* before __os_open */
  2046. #define    DB_TEST_SUBDB_LOCKS     10    /* subdb locking tests */
  2047.     int         test_abort;    /* Abort value for testing. */
  2048.     int         test_check;    /* Checkpoint value for testing. */
  2049.     int         test_copy;    /* Copy value for testing. */
  2050.  
  2051. #define    DB_ENV_AUTO_COMMIT    0x0000001 /* DB_AUTO_COMMIT. */
  2052. #define    DB_ENV_CDB        0x0000002 /* DB_INIT_CDB. */
  2053. #define    DB_ENV_CDB_ALLDB    0x0000004 /* CDB environment wide locking. */
  2054. #define    DB_ENV_CREATE        0x0000008 /* DB_CREATE set. */
  2055. #define    DB_ENV_DBLOCAL        0x0000010 /* DB_ENV allocated for private DB. */
  2056. #define    DB_ENV_DIRECT_DB    0x0000020 /* DB_DIRECT_DB set. */
  2057. #define    DB_ENV_DIRECT_LOG    0x0000040 /* DB_DIRECT_LOG set. */
  2058. #define    DB_ENV_DSYNC_LOG    0x0000080 /* DB_DSYNC_LOG set. */
  2059. #define    DB_ENV_FATAL        0x0000100 /* Doing fatal recovery in env. */
  2060. #define    DB_ENV_LOCKDOWN        0x0000200 /* DB_LOCKDOWN set. */
  2061. #define    DB_ENV_LOG_AUTOREMOVE   0x0000400 /* DB_LOG_AUTOREMOVE set. */
  2062. #define    DB_ENV_LOG_INMEMORY     0x0000800 /* DB_LOG_INMEMORY set. */
  2063. #define    DB_ENV_NOLOCKING    0x0001000 /* DB_NOLOCKING set. */
  2064. #define    DB_ENV_NOMMAP        0x0002000 /* DB_NOMMAP set. */
  2065. #define    DB_ENV_NOPANIC        0x0004000 /* Okay if panic set. */
  2066. #define    DB_ENV_OPEN_CALLED    0x0008000 /* DB_ENV->open called. */
  2067. #define    DB_ENV_OVERWRITE    0x0010000 /* DB_OVERWRITE set. */
  2068. #define    DB_ENV_PRIVATE        0x0020000 /* DB_PRIVATE set. */
  2069. #define    DB_ENV_REGION_INIT    0x0040000 /* DB_REGION_INIT set. */
  2070. #define    DB_ENV_RPCCLIENT    0x0080000 /* DB_RPCCLIENT set. */
  2071. #define    DB_ENV_RPCCLIENT_GIVEN    0x0100000 /* User-supplied RPC client struct */
  2072. #define    DB_ENV_SYSTEM_MEM    0x0200000 /* DB_SYSTEM_MEM set. */
  2073. #define    DB_ENV_THREAD        0x0400000 /* DB_THREAD set. */
  2074. #define    DB_ENV_TIME_NOTGRANTED    0x0800000 /* DB_TIME_NOTGRANTED set. */
  2075. #define    DB_ENV_TXN_NOSYNC    0x1000000 /* DB_TXN_NOSYNC set. */
  2076. #define    DB_ENV_TXN_WRITE_NOSYNC    0x2000000 /* DB_TXN_WRITE_NOSYNC set. */
  2077. #define    DB_ENV_YIELDCPU        0x4000000 /* DB_YIELDCPU set. */
  2078.     u_int32_t flags;
  2079. };
  2080.  
  2081. #ifndef DB_DBM_HSEARCH
  2082. #define    DB_DBM_HSEARCH    0        /* No historic interfaces by default. */
  2083. #endif
  2084. #if DB_DBM_HSEARCH != 0
  2085. /*******************************************************
  2086.  * Dbm/Ndbm historic interfaces.
  2087.  *******************************************************/
  2088. typedef struct __db DBM;
  2089.  
  2090. #define    DBM_INSERT    0        /* Flags to dbm_store(). */
  2091. #define    DBM_REPLACE    1
  2092.  
  2093. /*
  2094.  * The DB support for ndbm(3) always appends this suffix to the
  2095.  * file name to avoid overwriting the user's original database.
  2096.  */
  2097. #define    DBM_SUFFIX    ".db"
  2098.  
  2099. #if defined(_XPG4_2)
  2100. typedef struct {
  2101.     char *dptr;
  2102.     size_t dsize;
  2103. } datum;
  2104. #else
  2105. typedef struct {
  2106.     char *dptr;
  2107.     int dsize;
  2108. } datum;
  2109. #endif
  2110.  
  2111. /*
  2112.  * Translate NDBM calls into DB calls so that DB doesn't step on the
  2113.  * application's name space.
  2114.  */
  2115. #define    dbm_clearerr(a)        __db_ndbm_clearerr_rpmdb(a)
  2116. #define    dbm_close(a)        __db_ndbm_close_rpmdb(a)
  2117. #define    dbm_delete(a, b)    __db_ndbm_delete_rpmdb(a, b)
  2118. #define    dbm_dirfno(a)        __db_ndbm_dirfno_rpmdb(a)
  2119. #define    dbm_error(a)        __db_ndbm_error_rpmdb(a)
  2120. #define    dbm_fetch(a, b)        __db_ndbm_fetch_rpmdb(a, b)
  2121. #define    dbm_firstkey(a)        __db_ndbm_firstkey_rpmdb(a)
  2122. #define    dbm_nextkey(a)        __db_ndbm_nextkey_rpmdb(a)
  2123. #define    dbm_open(a, b, c)    __db_ndbm_open_rpmdb(a, b, c)
  2124. #define    dbm_pagfno(a)        __db_ndbm_pagfno_rpmdb(a)
  2125. #define    dbm_rdonly(a)        __db_ndbm_rdonly_rpmdb(a)
  2126. #define    dbm_store(a, b, c, d) \
  2127.     __db_ndbm_store_rpmdb(a, b, c, d)
  2128.  
  2129. /*
  2130.  * Translate DBM calls into DB calls so that DB doesn't step on the
  2131.  * application's name space.
  2132.  *
  2133.  * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
  2134.  * replaced the dbm interface with ndbm, and are not supported here.
  2135.  */
  2136. #define    dbminit(a)    __db_dbm_init_rpmdb(a)
  2137. #define    dbmclose    __db_dbm_close_rpmdb
  2138. #if !defined(__cplusplus)
  2139. #define    delete(a)    __db_dbm_delete_rpmdb(a)
  2140. #endif
  2141. #define    fetch(a)    __db_dbm_fetch_rpmdb(a)
  2142. #define    firstkey    __db_dbm_firstkey_rpmdb
  2143. #define    nextkey(a)    __db_dbm_nextkey_rpmdb(a)
  2144. #define    store(a, b)    __db_dbm_store_rpmdb(a, b)
  2145.  
  2146. /*******************************************************
  2147.  * Hsearch historic interface.
  2148.  *******************************************************/
  2149. typedef enum {
  2150.     FIND, ENTER
  2151. } ACTION;
  2152.  
  2153. typedef struct entry {
  2154.     char *key;
  2155.     char *data;
  2156. } ENTRY;
  2157.  
  2158. #define    hcreate(a)    __db_hcreate_rpmdb(a)
  2159. #define    hdestroy    __db_hdestroy_rpmdb
  2160. #define    hsearch(a, b)    __db_hsearch_rpmdb(a, b)
  2161.  
  2162. #endif /* DB_DBM_HSEARCH */
  2163.  
  2164. #if defined(__cplusplus)
  2165. }
  2166. #endif
  2167. #endif /* !_DB_H_ */
  2168.  
  2169. /* DO NOT EDIT: automatically built by dist/s_include. */
  2170. #ifndef    _DB_EXT_DEF_IN_
  2171. #define    _DB_EXT_DEF_IN_
  2172.  
  2173. /*@-declundef -noparams -fcnuse@*/
  2174. #define    db_create db_create_rpmdb
  2175. #define    db_strerror db_strerror_rpmdb
  2176. #define    db_env_create db_env_create_rpmdb
  2177. #define    db_version db_version_rpmdb
  2178. #define    log_compare log_compare_rpmdb
  2179. #define    db_env_set_func_close db_env_set_func_close_rpmdb
  2180. #define    db_env_set_func_dirfree db_env_set_func_dirfree_rpmdb
  2181. #define    db_env_set_func_dirlist db_env_set_func_dirlist_rpmdb
  2182. #define    db_env_set_func_exists db_env_set_func_exists_rpmdb
  2183. #define    db_env_set_func_free db_env_set_func_free_rpmdb
  2184. #define    db_env_set_func_fsync db_env_set_func_fsync_rpmdb
  2185. #define    db_env_set_func_ftruncate db_env_set_func_ftruncate_rpmdb
  2186. #define    db_env_set_func_ioinfo db_env_set_func_ioinfo_rpmdb
  2187. #define    db_env_set_func_malloc db_env_set_func_malloc_rpmdb
  2188. #define    db_env_set_func_map db_env_set_func_map_rpmdb
  2189. #define    db_env_set_func_pread db_env_set_func_pread_rpmdb
  2190. #define    db_env_set_func_pwrite db_env_set_func_pwrite_rpmdb
  2191. #define    db_env_set_func_open db_env_set_func_open_rpmdb
  2192. #define    db_env_set_func_read db_env_set_func_read_rpmdb
  2193. #define    db_env_set_func_realloc db_env_set_func_realloc_rpmdb
  2194. #define    db_env_set_func_rename db_env_set_func_rename_rpmdb
  2195. #define    db_env_set_func_seek db_env_set_func_seek_rpmdb
  2196. #define    db_env_set_func_sleep db_env_set_func_sleep_rpmdb
  2197. #define    db_env_set_func_unlink db_env_set_func_unlink_rpmdb
  2198. #define    db_env_set_func_unmap db_env_set_func_unmap_rpmdb
  2199. #define    db_env_set_func_write db_env_set_func_write_rpmdb
  2200. #define    db_env_set_func_yield db_env_set_func_yield_rpmdb
  2201. #define    db_sequence_create db_sequence_create_rpmdb
  2202. #if DB_DBM_HSEARCH != 0
  2203. #define    __db_ndbm_clearerr __db_ndbm_clearerr_rpmdb
  2204. #define    __db_ndbm_close __db_ndbm_close_rpmdb
  2205. #define    __db_ndbm_delete __db_ndbm_delete_rpmdb
  2206. #define    __db_ndbm_dirfno __db_ndbm_dirfno_rpmdb
  2207. #define    __db_ndbm_error __db_ndbm_error_rpmdb
  2208. #define    __db_ndbm_fetch __db_ndbm_fetch_rpmdb
  2209. #define    __db_ndbm_firstkey __db_ndbm_firstkey_rpmdb
  2210. #define    __db_ndbm_nextkey __db_ndbm_nextkey_rpmdb
  2211. #define    __db_ndbm_open __db_ndbm_open_rpmdb
  2212. #define    __db_ndbm_pagfno __db_ndbm_pagfno_rpmdb
  2213. #define    __db_ndbm_rdonly __db_ndbm_rdonly_rpmdb
  2214. #define    __db_ndbm_store __db_ndbm_store_rpmdb
  2215. #define    __db_dbm_close __db_dbm_close_rpmdb
  2216. #define    __db_dbm_delete __db_dbm_delete_rpmdb
  2217. #define    __db_dbm_fetch __db_dbm_fetch_rpmdb
  2218. #define    __db_dbm_firstkey __db_dbm_firstkey_rpmdb
  2219. #define    __db_dbm_init __db_dbm_init_rpmdb
  2220. #define    __db_dbm_nextkey __db_dbm_nextkey_rpmdb
  2221. #define    __db_dbm_store __db_dbm_store_rpmdb
  2222. #endif
  2223. #if DB_DBM_HSEARCH != 0
  2224. #define    __db_hcreate __db_hcreate_rpmdb
  2225. #define    __db_hsearch __db_hsearch_rpmdb
  2226. #define    __db_hdestroy __db_hdestroy_rpmdb
  2227. #endif
  2228. #define db_xa_switch db_xa_switch_rpmdb
  2229.  
  2230. #endif /* !_DB_EXT_DEF_IN_ */
  2231.  
  2232. /* DO NOT EDIT: automatically built by dist/s_include. */
  2233. #ifndef    _DB_EXT_PROT_IN_
  2234. #define    _DB_EXT_PROT_IN_
  2235.  
  2236. #if defined(__cplusplus)
  2237. extern "C" {
  2238. #endif
  2239.  
  2240. int db_create __P((DB **, DB_ENV *, u_int32_t));
  2241. char *db_strerror __P((int));
  2242. int db_env_create __P((DB_ENV **, u_int32_t));
  2243. char *db_version __P((int *, int *, int *));
  2244. int log_compare __P((const DB_LSN *, const DB_LSN *));
  2245. int db_env_set_func_close __P((int (*)(int)));
  2246. int db_env_set_func_dirfree __P((void (*)(char **, int)));
  2247. int db_env_set_func_dirlist __P((int (*)(const char *, char ***, int *)));
  2248. int db_env_set_func_exists __P((int (*)(const char *, int *)));
  2249. int db_env_set_func_free __P((void (*)(void *)));
  2250. int db_env_set_func_fsync __P((int (*)(int)));
  2251. int db_env_set_func_ftruncate __P((int (*)(int, off_t)));
  2252. int db_env_set_func_ioinfo __P((int (*)(const char *, int, u_int32_t *, u_int32_t *, u_int32_t *)));
  2253. int db_env_set_func_malloc __P((void *(*)(size_t)));
  2254. int db_env_set_func_map __P((int (*)(char *, size_t, int, int, void **)));
  2255. int db_env_set_func_pread __P((ssize_t (*)(int, void *, size_t, off_t)));
  2256. int db_env_set_func_pwrite __P((ssize_t (*)(int, const void *, size_t, off_t)));
  2257. int db_env_set_func_open __P((int (*)(const char *, int, ...)));
  2258. int db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
  2259. int db_env_set_func_realloc __P((void *(*)(void *, size_t)));
  2260. int db_env_set_func_rename __P((int (*)(const char *, const char *)));
  2261. int db_env_set_func_seek __P((int (*)(int, off_t, int)));
  2262. int db_env_set_func_sleep __P((int (*)(u_long, u_long)));
  2263. int db_env_set_func_unlink __P((int (*)(const char *)));
  2264. int db_env_set_func_unmap __P((int (*)(void *, size_t)));
  2265. int db_env_set_func_write __P((ssize_t (*)(int, const void *, size_t)));
  2266. int db_env_set_func_yield __P((int (*)(void)));
  2267. int db_sequence_create __P((DB_SEQUENCE **, DB *, u_int32_t));
  2268. #if DB_DBM_HSEARCH != 0
  2269. int     __db_ndbm_clearerr __P((DBM *));
  2270. void     __db_ndbm_close __P((DBM *));
  2271. int     __db_ndbm_delete __P((DBM *, datum));
  2272. int     __db_ndbm_dirfno __P((DBM *));
  2273. int     __db_ndbm_error __P((DBM *));
  2274. datum __db_ndbm_fetch __P((DBM *, datum));
  2275. datum __db_ndbm_firstkey __P((DBM *));
  2276. datum __db_ndbm_nextkey __P((DBM *));
  2277. DBM    *__db_ndbm_open __P((const char *, int, int));
  2278. int     __db_ndbm_pagfno __P((DBM *));
  2279. int     __db_ndbm_rdonly __P((DBM *));
  2280. int     __db_ndbm_store __P((DBM *, datum, datum, int));
  2281. int     __db_dbm_close __P((void));
  2282. int     __db_dbm_delete __P((datum));
  2283. datum __db_dbm_fetch __P((datum));
  2284. datum __db_dbm_firstkey __P((void));
  2285. int     __db_dbm_init __P((char *));
  2286. datum __db_dbm_nextkey __P((datum));
  2287. int     __db_dbm_store __P((datum, datum));
  2288. #endif
  2289. #if DB_DBM_HSEARCH != 0
  2290. int __db_hcreate __P((size_t));
  2291. ENTRY *__db_hsearch __P((ENTRY, ACTION));
  2292. void __db_hdestroy __P((void));
  2293. #endif
  2294.  
  2295. #if defined(__cplusplus)
  2296. }
  2297. #endif
  2298. #endif /* !_DB_EXT_PROT_IN_ */
  2299.